Assuming that IUncle is an interface that Uncle implement. Assumming that I don't wont to use concrete classes inside the class Child because I want Child to be use with any implementation of Iuncle. How can I change the implementation of Child (below) in the way that will work for any implemtation of Uncle.
public class Child {
private List<IUncle> uncles;
public Child(List<IUncle> uncles){
this.uncles = uncles;
}
public void addUncle(IUncle uncle) {
this.uncles.add(uncle);
}
}
In the main class, I use this class like this:
List<Uncle> uncles = new ArrayList<Uncle>();
Child oneChild = new Child(uncles);
oneChild.addUncle(new Uncle);
This is doesn't work at all !!!
Please, can someone give the proper way to deal with this situation in java ?