Open–closed principle
This principle state "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" It means that when you think about the architecture of your program, you have to think about a way to make it easy for any developer to add different functionality by just adding code without having to modify (remove or modify) the existing code.
Code example
In the previous implementation, if the user want to add a medium dog, he has to modify an existing method. In the following version, the user doesn't have to modify existing code. Like you can see here, a good way to implement the the open-close principle is to use abstract interface.References
- https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle
- "Clean Architecture: A Craftsman's Guide to Software Structure and Design" by Robert Martin