remember pie which, stands for Polymorphism, Inheritance and Encapsulation are the 3 pillars of OOPL
Q. Which one to favor, composition or inheritance? The guide is that inheritance should be only used when
subclass ‘is a’ superclass.
- Don’t use inheritance just to get code reuse. If there is no ‘is a’ relationship then use composition for code reuse. Overuse of implementation inheritance (uses the “extends” key word) can break all the subclasses, if the superclass is modified.
Do not use inheritance just to get polymorphism. If there is no ‘is a’ relationship and all you want is
polymorphism then use interface inheritance with composition, which gives you code reuse (Refer Q10 in Java section for interface inheritance).
Set (HashSet , TreeSet)
List (ArrayList, LinkedList, Vector etc)
Map(HashMap, TreeMap and Hashtable)
