Deeper SOLID refactoring
We can take the OCP of the SOLID principles further by using an abstract base class that all audio player classes derive from. This can add further required implementations and default behavior and would then be a classic object-oriented programming (OOP) inheritance example.
OOP SOLID principles reminder
In OOP, the derived class inherits all base class members and can also add its members. However, it’s essential to keep the Liskov substitution principle of the SOLID principles in mind when using derived classes. The L principle states that objects of a base class should be replaceable with objects of a derived class without changing the correctness of the program. In simpler terms, any program that uses a base class reference should be able to use any derived classes without knowing it. For OOP, this is polymorphism, which allows us to write more general code that works with any audio-playing class.
Let’s take a look at how we might...