Design Pattern: Strategy
While designing application, if there are some aspects of the code that changes with new requirements, so this behavior needs to be pulled out and separated from all other aspects that doesn’t change. The varying part may be encapsulated and later it can be altered or extended without affecting the other.
To make things flexible, it is better to decide the behavior at run time and is possible with interface i.e programming to the Super Type . The declared variable type usually abstract class or interface and in run time any concrete class implementation of the super type can be assigned.
Inheritance is not always good. In stead of using inheritance many time the behavior of the system can be splited into multiple classes and all these classes can be used to result a composition. Creating a system with composition provides a lot many flexibility.