"Solid" is an acronym that stands for five principles of object-oriented software design, which were introduced by Robert C. Martin in his book "Agile Software Development: Principles, Patterns, and Practices."
Single Responsibility Principle (SRP): A class should have only one reason to change.
Here in srp
the class Journal has only one responsibility which is maintaining journal entries and providing add and remove entry functionality. PersistenceManager is responsible for saving the journal entries to a file. This way if the requirement changes or any bug found in file saving, it would not affect the Journal class and the changes would be in the PersistenceManager only.
Open-Closed Principle (OCP): A class should be open for extension but closed for modification.
Here, the Shape
class is open for extension (new classes can inherit from it, such as Square
and Circle
), but closed for modification (we don't need to change the Shape class in order to add new shapes).
Liskov Substitution Principle (LSP): Subtypes should be substitutable for their base types.