Friday, March 29, 2019

Object Oriented Design Principles

The famous Head First Design Pattern book discusses 9 important Object Oriented Design principles.

Here are the summary of the those principle:
  1. Identify the aspects of your application that vary and separate them from what stays the same. Encapsulate what varies.
  2. Favor composition over inheritance.
  3. Program to an interface, not an implementation.
  4. Strive for loosely coupled designs between objects that interact.
  5. Classes should be open for extension, but closed for modification.
  6. 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.
  7. Principle of Least Knowledge - talk only to your immediate friends.
  8. The Hollywood principle - Don't call us, we'll call you.
  9. A class should have only one reason to change.

No comments:

Post a Comment