S.O.L.I.D. Class Design Principles
- S ingle Responsibility Principle (SRP) - Each responsibility should be a class
- O pen/Closed Principle (OCP) - Inherit from abstract base classes
- L iskov substitution principle (LSP) - Subtypes should be substitutable for their supertypes
- I nterface Segregation Principle (ISP) - Use many small interfaces, not one big
- D ependency Inversion Principle (DIP) - Let details depend upon abstractions, not the other way around
More Principles
- Law of Demeter: Only interact with yourself and your neighbours
- Hollywood Principle: Don't call us, we'll call you - Reduce coupling using events, IoC, DI etc
- Don’t Repeat Yourself (DRY): Remove duplication, not only in code but also in your model
- Program to an interface, not an implementation: Decouple implementation from interfaces
- You Ain’t Gonna Need It (YAGNI): Wait until you need it
- Keep It Simple, Stupid (KISS): Make everything as simple as possible, but not simpler
- Encapsulation and Information Hiding: Protect yourself, be shy, don't reveal your inner mechanisms
- Separation of Concerns (SoC): Separate stuff using encapsulation, subsystems, modules, layers etc
- High Cohesion:
- Low/Loose coupling: Let your components be independent of each other
- Command-query separation (CQS)
- Design by Contract (DbC)
- Dependency Injection (DI)
- Inversion of Control (IoC)
No comments:
Post a Comment