Encapsulate what varies
- Identify the aspects of the application that vary and separate them
- Basis for almost every design pattern
Prefer interfaces, not concrete classes
- Provides higher level of decoupling
- Allows for Polymorphism
Prefer Has-A over Is-A
- Favour composition over Inheritance
- Change behaviour at runtime
Build loosely coupled systems
- Minimize inter-dependency btw objects
- Flexible and scalable Object Oriented systems
Open-closed principle
- Classes should be open for extension and closed for modification
- If requirements change extend the class don’t modify it
Dependency Inversion principle
- Depend upon abstractions not concrete classes
- High level components should not be dependent on low level objects but rather on abstraction
Principle of Least Knowledge
- Reduce interactions btw objects to very few close classes
- Prevent designs in which a large number of classes are coupled together
- From an object method invoke only,
- Object itself
- Any component of the object
- Objects passed in as parameter to the method
- Objects created by the method
The Hollywood Principle
- Don’t call us we will call you
- High level components decide when and how low level components are needed
- Similar to dependency inversion (both achieve decoupling)
- Prevents dependency rot
Single Responsibility
- A class should have only one responsibility
- High cohesion
- Class methods should all be involved in one area of change