Design pattern: Polymorphism for list of objects
- by ziang
Suppose I have a class A, and A1, A2 inherits from A.
There are 2 functions:
List<A1> getListA1(){...}
List<A2> getListA2(){...}
Now I want to do something similar to both A1 and A2 in another function
public void process(List<A>){...}
If I want to pass the instance of either ListA1 or ListA2, of course the types doesn't…