Etl Testing Notes33
Etl Testing Notes33
INTERFACES
Interfaces
What is an Interface?
Creating an Interface
Implementing an Interface
Inheritance
What is an Interface?
Why not just use abstract classes? Java does not permit
multiple inheritance from classes, but permits
implementation of multiple interfaces.
What is an Interface?
Why an Interface?
Why an Interface?
Creating an Interface
File InterfaceName.java:
modifier interface InterfaceName
{
constants declarations;
methods signatures;
}
Creating an Interface
public interface MyInterface
{
public void aMethod1(int i); // an abstract methods
public void aMethod2(double a);
...
public void aMethodN();
}
public Class
{
public void
public void
...
public void
}
Comparable Circle
public interface Comparable
{
public int compareTo(Object obj);
}
public Class Circle extends Shape
implements Comparable {
public int compareTo(Object o) {
if (getRadius() > ((Circle)o).getRadius())
return 1;
else if (getRadius()<((Circle)o).getRadius())
return -1;
else
return 0;
}
}
Comparable Cylinder
public Class Cylinder extends Circle
implements Comparable {
public int compareTo(Object o) {
if(findVolume() > ((Cylinder)o).findVolume())
return 1;
else if(findVolume()<((Cylinder)o).findVolume())
return -1;
else
return 0;
}
}
Using Interface
This is one of the key features of interfaces.
Using Interface
Objective: Use the findMax() method to find a
maximum circle between two circles:
Circle circle1 = new Circle(5);
Circle circle2 = new Circle(10);
Comparable circle = Max.findMax(circle1, circle2);
System.out.println(((Circle)circle).getRadius());
// 10.0
System.out.println(circle.toString());
// [Circle] radius = 10.0
Interface1_1
Object
Interface2_2
Interface1
Class1
Interface2_1
Class2
Interface1_2
public Interface1_2 { }
Interface1_1
Interface2_2
Interface1
Interface2_1
public Interface2_1 { }
public Interface2_2 { }
Object
Class1
Class2