
Law Demeter
Talk only with your close friends.
Avoid code like that: School.GetWorkers().GetPersonData().GetName(). Every method can only call methods of:
- Its object.
- Parameters of its method.
- Objects, which it creates.
- Fields of its object
Advantages
- Less dependency between classes and modules.
- Easier maintenance.
- Lack of knowing details of calling objects.
Disadvantages
- Classes should have more methods.
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://medium.com/better-programming/demeters-law-don-t-talk-to-strangers-87bb4af11694
- https://pl.wikipedia.org/wiki/Prawo_Demeter
- https://en.wikipedia.org/wiki/Law_of_Demeter
- https://devcave.pl/notatnik-juniora/zasady-projektowania-kodu#lod—law-of-demeter
Sorry, there was a YouTube error.