Design Principles


1. Identify the aspects of your application that vary and separate them from what stays the same.

Take what varies and encapsulate it so it won’t affect the rest of your code

The result is : Fewer unintended consequences from code changes and more flexibility in your systmes

2. Program to an interface (super type), not an implementation.

 

3. Favor composition over inheritance.

‘Has a’ can be better than ‘Is a’

 

4. Strive for loosely coupled designs between objects that interact.

Loosely coupled designs allow us to build flexible OO systems that can handle change because they minimize the inter-dependency between objects.

 

5. Classes should be open for extension, but closed for modification.

 

6. Depend upon abstractions. Do not depend upon concrete classes.

This is the Dependency Inversion Principle. High level components should not depend on low level components, instead they should both depend on abstractions. * Factory Method adheres to the dependency inversion principle.

Why it is called Dependency Inversion?
Normally higher level components depends on lower level components. After adhering to this principle, lower level components depends on higher level abstraction. So the top to bottom dependency chart has inverted itself and both higher level and lower level components start depending on abstraction.

Advertisements