SOLID principles are basic rules of object-oriented programming. You should not only know them but also practice and use them at work. At first, I remind you of SOLID principles, and then I show you some exercises.
Single responsibility principle
Every class should have only one responsibility (every class should have only one reason to change) — one purpose of existence.
All classes should be open for enlargement and closed for modifications.
Liskov substitution principle
The application should work correctly when we put in the base class place every derived class.
Interface segregation principle
Many small and dedicated interfaces are better than few and general.
Dependency inversion principle
High-level modules should not depend on low-level modules, but the dependence should result from abstraction.
SOLID principles exercises
- Write code and think about principles.
- Sometimes read SOLID principles.
- Read code other programmers and look for principles there.
- Observe, how your code is changing. If SOLID principles help to handle changes, or they cause bigger problems.
- Read code with examples of principles.
- Give your code to review and ask reviewer about principles
Check sites with SOLID exercises:
All posts from mini project: Learn SOLID and OOP principles:
- SOLID exercises
- S like Single responsibility principle
- SOLID exercises — Kata
- O as Open-closed principle
- L jak Liskov Substitution Principle
- Interface segregation principle
- KISS — Keep it simple, stupid
- DRY — Don’t repeat yourself
- Dependency inversion principle
- SLAP — Single Level of Abstraction Principle
- Composition Over Inheritance
- Encapsulate what changes
- Lod — Law of Demeter
- ES as Exercises of Single responsibility principle
- EO as Exercises of Open/closed principle
- EL as Exercises of Liskov Substitution Principle
- EI as Eexrcises of Interface segregation principle
- ES as Exercises of Dependency Inversion Principle
- Object-oriented programming
- OOP — Object-Oriented Programming — Advice
- OOP — Object Oriented Programming
- Book: Clean architecture — Robert C. Martin