Inheritance is very useful, but also interrupts encapsulation. This means that your subclasses depend on the implementation details of the superclass; if the superclass changes, your subclass may break. Here is an example in Java, from Effective Java from Josh Bloch:
public class InstrumentedHashSet<E> extends HashSet<E> {
The problem is that the hashSet addAll () method uses its add () method internally, but does not document this. Therefore, if you try
InstrumentedHashSet<String> s = new InstrumentedHashSet<String>(); s.addAll(Arrays.asList("Snap", "Crackle", "Pop"));
you get the score 6 instead of 3. In this particular case, this is not very harmful, but if you add a large collection or perform some other operation, it may be.
Thus, concrete classes are usually not a good idea for inheritance, unless they are designed for subclasses.
source share