Encapsulate what may change
Hide changing code under abstraction.
Examples:
Tickets: We can hide condition like is the ticket valid in a separate method.
Animals: Animals (Cat, Dog) have a voice. We have a class AnimalConcert. It calls all animal voices. In this method, AnimalsConcert iterate through all animals, check their type and give a voice for it.
We can add an interface IAnimal with method GetVoice. All animals can implement it. The implementation of giving voice is moved from AnimalsConcert to Dog and Cat. Now, AnimalsConcert iterates through all animals and call their method GetVoice. Now, when we add a new animal, we should only add a class with this new animal. We shouldn’t change AnimalConcert implementation.
Advantages
- Less code to modify when making changes.
- Clients depend on abstraction, not on low-level details (the Dependency Inversion Principle).
- Easier maintenance.
- Easier testing
Disadvantages
- More abstractions.
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
- https://devcave.pl/notatnik-juniora/zasady-projektowania-kodu
- https://medium.com/@iamprabal/encapsulation-4f5392d172a3
- https://pl.cs.jhu.edu/oose/lectures/design-principles.shtml
1
/
42
KB_ZW_0181 - Refleksje Na Temat Zarządzania Wiedzą: Radość
Jeden Popup Do Tworzenia i Edycji - Same Popup for Creating and Editing| Bubble.io TUTORIAL
Adam Haertle – [PL] Katalog złych praktyk – Notatka z nauki
Inwestowanie w Startupy – Bartłomiej Gola (SpeedUP Group) – Notatka z nauki
Oceń Gwiazdkami - Star Rating Input| Bubble.io TUTORIAL
Wyślij Dane i Pokaż w Popupie przez URL - Send Data and Show Popups via Url| Bubble.io TUTORIAL
Uber i “Dolina Krzemowa” – Kacper Winiarczyk (Uber) – Notatka z nauki
Helen Pryłowska “O tym czego nie widać” – Notatka z nauki
Funkcjonalność: Polubienia - Like Functionality| Bubble.io TUTORIAL
Unscripted Życie wolność przedsiębiorczość — MJ DeMarco – Notatka z nauki
Głaskologia — Miłosz Brzeziński – Notatka z nauki
Lista Rozwijana Do Sortowania Listy - Dropdown to Sort a Repeating Group| Bubble.io TUTORIAL
Start-up po polsku Jak założyć i rozwinąć dochodowy e-biznes
Czy Blockchain zdecentralizuje wszystko – Notatka z nauki
Wyświetlanie Wybranego Elementu Na Stronie - Display the Selected Thing on Page | Bubble.io TUTORIAL
Pasek Postępu - Create a Progress Bar| Bubble.io TUTORIAL
KB_ZW_0180 - Refleksje Na Temat Zarządzania Wiedzą: Szczegóły
Dalszy Rozwój Aplikacji - Next Steps| Bubble.io TUTORIAL
Ewolucja z monolitu do architektury opartej na zdarzeniach – Notatka z nauki
Lead generation i automatyzacja, czyli jak sprzedawać leżąc na plaży – Notatka z nauki
Reguły Prywatności - Privacy Rules| Bubble.io TUTORIAL
Nawigacja Aplikacji - Navigation Logic| Bubble.io TUTORIAL
9 rzeczy których nauczyłem się robiąc startupy – Notatka z nauki
5 Najczęstszych błędów w Entity Framework Core – Notatka z nauki
Użytkownicy - Users| Bubble.io TUTORIAL
Bitcoin i inne kryptowaluty – Maciej Ołpiński – Notatka z nauki
SaaS w Polsce – blaski i cienie – Michał Sadowski – Brand24 – Notatka z nauki
Filtrowanie Danych - Filters Reusable| Bubble.io TUTORIAL
Wyszukiwanie - Search Functionality| Bubble.io TUTORIAL
Stany (Dane) Tymczasowe - Custom States| Bubble.io TUTORIAL
1
/
42