- Abstraction
- Encapsulation
- Polymorphism
- Inheritance
- Encapsulate what varies
- Favor composition over inheritence
- Program to interfaces, not implementations
- Strive for loosely coupled designs between objects that interact
- Classes should be open for extension, but closed for modification
- Depend upon abstractions. Do not depend upon concrete classes. Dependency Inversion Principle
- Principle of Least Knowledge - talk only to your immediate friends.
The following guidelines can help you avoid OO designs that violate the 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.
we should only invoke methods that belongs to:
- The object itself
- Objects passed in as a parameter to the method
- Any object the method creates or instantiates
- Any components of the object