If you are a developer, you must have at least a basic idea about Object Oriented Programming. But, if you are a willing to become an OOP programmer, it’s a requirement to you putting enough efforts on learning the concepts of Object Oriented Design Principles to create clean and modular designs. And it’s curious how things raised more than decades ago can be still updated.
“Patterns of Enterprise Application Architecture” – Martin Fowler.
“Principles Of Object Oriented Design“, compiled by Uncle Bob.
Principles about class design (SOLID):
|SRP||The Single Responsibility Principle||A class should have one, and only one, reason to change.|
|OCP||The Open Closed Principle||You should be able to extend a classes behavior, without modifying it.|
|LSP||The Liskov Substitution Principle||Derived classes must be substitutable for their base classes.|
|ISP||The Interface Segregation Principle||Make fine grained interfaces that are client specific.|
|DIP||The Dependency Inversion Principle||Depend on abstractions, not on concretions.|
Principles about package cohesion:
|REP||The Release Reuse Equivalency Principle||The granule of reuse is the granule of release.|
|CCP||The Common Closure Principle||Classes that change together are packaged together.|
|CRP||The Common Reuse Principle||Classes that are used together are packaged together|
Principles about the couplings between packages:
|ADP||The Acyclic Dependencies Principle||The dependency graph of packages must have no cycles.|
|SDP||The Stable Dependencies Principle||Depend in the direction of stability.|
|SAP||The Stable Abstractions Principle||Abstractness increases with stability|
Besides that, there are a bulck of others object oriented design principles that are equally important:
- DRY (Don’t repeat yourself) — avoids duplication in code.
- Encapsulate what changes — hides implementation detail, helps in maintenance.
- Favor Composition over Inheritance — code reuse without cost of inflexibility.
- Programming for Interface — helps in maintenance, improves flexibility.
- Delegation principle — don’t do all things by yourself, delegate it.