The famous Head First Design Pattern book discusses 9 important Object Oriented Design principles.
Here are the summary of the those principle:
- Identify the aspects of your application that vary and separate them from what stays the same. Encapsulate what varies.
- Favor composition over inheritance.
- Program to an interface, not an implementation.
- Strive for loosely coupled designs between objects that interact.
- Classes should be open for extension, but closed for modification.
- Depend on abstractions. Do not depend on concrete classes (Dependency Inversion Principle). Guidelines to achieve dependency inversion principle:
- No variable should hold a reference to a concrete class.
- No class should derive from a concrete class.
- No method should override an implemented method of any of its base classes.
- Principle of Least Knowledge - talk only to your immediate friends.
- The Hollywood principle - Don't call us, we'll call you.
- A class should have only one reason to change.
No comments:
Post a Comment