7 Common Programming Principles
1. KISS (Keep It Simple, Stupid)
2. DRY (Don’t Repeat Yourself)
3. YAGNI (You Aren’t Gonna Need It)
4. SOLID
5. Separation of Concerns (SoC)
6. Avoid Premature Optimization
7. Law of Demeter
SOLID
Single Responsibility Principle“A class should have only one reason to change” which means every class should have a single responsibility or single job or single purpose. In other words, a class should have only one job or purpose within the software system.
Open/Closed Principle
“Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification” which means you should be able to extend a class behavior, without modifying it.
Base Class that can be extended by other classes
Liskov Substitution Principle
“Derived or child classes must be substitutable for their base or parent classes“. This principle ensures that any class that is the child of a parent class should be usable in place of its parent without any unexpected behavior.
Interface Segregation Principle
“Do not force any client to implement an interface which is irrelevant to them“. Here your main goal is to focus on avoiding fat interface and give preference to many small client-specific interfaces.
Dependency Inversion Principle
“High-level modules should not depend on low-level modules. Both should depend on abstractions“
In simpler terms, the DIP suggests that classes should rely on abstractions (e.g., interfaces or abstract classes) rather than concrete implementations.
This allows for more flexible and decoupled code, making it easier to change implementations without affecting other parts of the codebase.
SOLID principles make code easier to maintain.
Principle allows developers to add new features without changing existing code, making it easier to adapt to new requirements.
SOLID encourages flexibility.