Previously, we had a look at the single responsibility principle. Hand in hand with this is the open/closed principle.
Bertrand Meyer stated that software entities (classes, modules, functions, and so on):
- Should be open for extension
- Should be closed for modification
What exactly does this mean? Let's take the PlayerStatistics class as an example. Inside this class, you know that we have a method to calculate the strike rate of a particular player. This is included in the class because it inherits from the Statistics abstract class. That is correct, but the fact that the CalculateStrikeRate(Player player) method caters for two player types (all-rounders and batsmen) is already a hint of a problem.
Let's assume that ...