/** * Author: Josiah Yoder et al. * Class: SE1021-031 * Lesson: Week 3, Day 2 */ package example3_2; /** * Illustrates an example of an interface * "CanBeCompared" is our own take on Java's java.lang.Comparable * with a different interface. */ public class Example { public static void main(String[] ignored) { // // NOTE: DOING IT THIS WAY CAUSED US TROUBLE WITH THE EXAMPLE // // Do you see why? // Drawable c1 = new Circle(0,0,1.0); // Drawable c2 = new Circle(0,0,1.0); Circle c1 = new Circle(0,0,1.0); Circle c2 = new Circle(0,0,1.0); // NOTE: We can do this (with Circle references) and it works just fine // We are just using the interface references to illustrate the concept. // Circle compared1 = c1; // Circle compared2 = c2; CanBeCompared compared1 = c1; CanBeCompared compared2 = c2; System.out.println("C1 is greater: "+c1.greaterThan(c2)); // At this point, we might go on to make a sorting algorithm that accepts "CanBeCompared" // e.g. Collections.sort expects objects to be "java.lang.Comparable" // // http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html // // http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html } }