Design Principles
Class Design Principles (S.O.L.I.D)
- Single responsibility (SRP)
- Open-closed (OCP)
- Liskov substitution (LSP)
- Interface segregation (ISP)
- Dependency inversion (DIP)
Package Cohesion Principles
- Reuse release equivalence (REP)
- Common closure (CCP)
- Common reuse (CRP)
Package Coupling Principles
- Acyclic dependencies (ADP)
- Stable dependencies (SDP)
- Stable abstractions (SAP)
YAGNI (You Ain’t Gonna Need It)
KISS (Keep It Simple Stupid)
DRY (Don’t Repeat Yourself)
WET (Write Everything Twice)
GRASP (General Responsibility Assignment Software Patterns)
- Creator
- Information Expert
- Low Coupling
- Controller
- High Cohesion
- Indirection
- Polymorphism
- Protected Variations
- Pure Fabrication
SLAP (Single Level of Abstraction Principles)
Curly’s Law (Do One Thing)
Favour Composition over Inheritance
Always favor composition over inheritance ,if possible. Composition allows to change behavior of a class at runtime by setting property during runtime and by using Interfaces to compose a class we use polymorphism which provides flexibility of to replace with better implementation any time.
Programming for Interface not implementation
Always program for interface and not for implementation this will lead to flexible code which can work with any new implementation of interface. So use interface type on variables, return types of method or argument type of methods in Java.
Delegation principle
Don’t do all stuff by yourself, delegate it to respective class. Classical example of delegation design principle is equals() and hashCode() method in Java.Benefit of this design principle is no duplication of code and pretty easy to modify behavior.
Hollywood Principle (don’t call us, we’ll call you)
Dependency Injection yada Inversion of Control olarakta bilinir.
The Dependency Injection pattern is an implementation of Dependency Inversion principle. It says “Don’t ask for dependency it will be provided to you by framework“.
Advantages of Dependency Injection:
- More Readable Code
- Loose Coupling
- More Testable Code
- More Reusable Code
Encapsulate What Changes
Only one thing is constant in software field and that is “Change”, So encapsulate the code you expect or suspect to be changed in future.
Benefit of this Design principle is that Its easy to test and maintain proper encapsulated code. If you are coding in Java then follow principle of making variable and methods private by default and increasing access step by step e.g. from private to protected and not public. Several of design patterns in Java use Encapsulation. Factory Design Pattern is one example of Encapsulation which encapsulate object creation code and provides flexibility to introduce new product later with no impact on existing code.
Principles of Good Software Design
- Simplicity
- Hide Complexity and Build Abstractions
- Avoid Overengineering
- Try Test-Driven Development
- Learn from Models of Simplicity in Software Design
- Loose Coupling
- Promoting Loose Coupling
- Avoiding Unnecessary Coupling
- Models of Loose Coupling
- Don’t Repeat Yourself (DRY)
- Copy and Paste Programming
- Coding to Contract
- Draw Diagrams
- Use Case Diagrams
- Class Diagrams
- Module Diagrams
- Single Responsibility
- Promoting Single Responsibility
- Examples of Single Responsibility
- Open-Closed Principle
- Dependency Injection
- Inversion of Control (IOC)
- Designing for Scale
- Adding More Clones
- Functional Partitioning
- Data Partitioning
- Design for Self-Healing
- Separation of Concerns
- Boy Scout Rule (Entropy, The Broken Window Theory)
- Conways Law (DevOps)