- A class should have one and only one reason to change, meaning that a class should only have one job.
- Define responsibilities
- Strive for high chohesion and loose coupling
- Keep classses small, focused, testable
- Objects or entities should be open for extension, but closed for modification.
- Open for extension means that we should be able to add new features or components to the application without breaking existing code.
- Closed for modification means that we should not introduce breaking changes to existing functionality, because that would force you to refactor a lot of existing code
- Balance abstraction and concreteness. Abstraction adds complexity. Predict where variation is needed and apply abstraction as needed.
- When you use new keyword, you are being concrete. new is glue. Dependency Injection..
- Implement new features in new classes. In this way, you can add behavior without touching existing code.
Liskov Substitution Principle
- Objects of a superclass shall be replaceable with objects of its subclasses without breaking the application.
- Subtypes must be substitutable for their base types.
- Tell, Don’t Ask: Rather than asking an object for data and acting on that data, we should instead tell an object what to do.
- A client should not be forced to implement an interface that it doesn’t use.
- A clien shouldn’t be forced to depend on methods they do not use.
- Split interfaces in behaviours. I….able interface.
- High level modules should not depend on low level modules. Both should depend on abstractions.
- Entities must depend on abstractions not on concretions.