Interface question in java
Hi
i have a question regarding interface
interface Igroup {
Igroup getAllGroups();
}
if i want to implement this interface i need to create new class and add
an implemenation to the getAllGroups()
i take this method without changing it;s signiture.
Class GroupImpl implements Igroup {
String name;
//define link list of the type Igroup.
LinkList<Igroup> group;
GroupImpl (String name) {
this.name=name;
this.group= new LinkList<Igroup>();
}
Igroup getAllGroups(){
return this.group;
}
My question is what is the idea behind defining the member of GroupImpl
as Igroup type.
why i can;t define it like this
Class GroupImpl implements Igroup {
String name;
LinkList<GroupImpl> group;
GroupImpl (String name) {
this.name=name;
this.group= new LinkList<GroupImpl>();
}
Igroup getAllGroups(){
return this.group;
}
this is not working because getAllGroups() expected Igroup type not GroupImpl
thougth GroupImpl implements Igroup.
what is the idea behind the concept of OOD to use the interface itself and not using the
son (that implements this interface)
Best Regards