Spis treści
SOLID
SOLID is a basic concept in object-oriented programming. It was introduced by Robert C. Martin, who gathered together five rules in one concept: SOLID. It is an acronym of 5 principles for good object-oriented programming:
- Single responsibility principle
- Open/closed principle
- Liskov substitution principle
- Interface segregation principle
- Dependency inversion principle
Single responsibility principle
Every class should have only one responsibility (every class should have only one reason to change) — one purpose of existence.
Open/closed principle
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.
Advantages
- Better code readability.
- Higher quality.
- Cheaper maintenance.
- Fewer bugs during development.
- Easier testing.
- Easier developing.
- Lack of god-classes.
Disadvantages
- Bigger effort during developing.
Summary
Use SOLID principles everywhere you can. These are the best practices. In special situations allow yourself to not use these rules to write code faster. Despite breaking SOLID, try to write good code.
All posts from mini project: Learn SOLID and OOP principles:
- SOLID
- 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
Sources
Main image
Materials
- http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
- https://en.wikipedia.org/wiki/SOLID
- https://pl.wikipedia.org/wiki/SOLID_(programowanie_obiektowe)
- https://www.samouczekprogramisty.pl/solid-czyli-dobre-praktyki-w-programowaniu-obiektowym/
- https://www.p-programowanie.pl/paradygmaty-programowania/zasady-solid/
- https://javadeveloper.pl/solid/
- https://sii.pl/blog/solid-dobre-praktyki-programowania/
- https://devcave.pl/notatnik-juniora/zasady-projektowania-kodu
Like!! I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest.