I thought all were in 'is-a' relations, cause "implements" also counts as 'is-a'.
I agree with you here. IMHO as long as an inheritance relationship holds between class to class, interface to class, and interface to interface, an
is a relationship holds.
A. interface Person
class Employee implements Person
Employee e = new Employee();
// (e instanceof Person)==true
B. interface Shape
interface Rectangle extends Shape
// Class MyGrid implements Rectangle
Rectangle r = new MyGrid();
// (r instanceof Shape)==true
C. interface Component
class Object implements Component{Component[] Component;}
???
There is already a java.lang.Object class. Okay, assuming you made your own Object class,
com.anup.Object obj = new com.anup.Object();
// (obj instanceof Component)==true
The
has a relationship implies aggregation, e.g.,
class Employee implements Person
{
String employeeNumber;
// etc
}
Employee e has an employeeNumber, but employeeNumber instanceof Employee (no!),
employeeNumber instanceof Person (no!)
It is legal to do this (but it might get confusing
)
interface Person
{
// etc.
}
class Employee implements Person
{
Person p;
// etc.
}
in which case an Employee e
is a Person, while at the same time
has a Person p.
-anthony
[ March 30, 2002: Message edited by: Anthony Villanueva ]
[ March 30, 2002: Message edited by: Anthony Villanueva ]