Upload
ismael
View
341
Download
0
Embed Size (px)
Citation preview
by Ismael Soares @rkmael
Law of Demeter
What’s it?The Law of Demeter (LoD) or principle of least knowledge is a design guideline for developing software
(https://en.wikipedia.org/wiki/Law_of_Demeter)
The OriginThe guideline was proposed at Northeastern University towards the end of 1987
Demeter is not a man, is a Greek goddess!
It is so named for its origin in the Demeter Project, an adaptive programming and aspect-‐oriented programming effort.
It means a philosophy of bottom-up
LoD Principle:• Each unit should have only limited knowledge about other units:
only units "closely" related to the current unit.
• Each unit should only talk to its friends; don't talk to strangers.
• Only talk to your immediate friends.
Advantages:• More maintainable
• More adaptable
• Less dependence
• Very useful in layered architecture
Disadvantages:• More code
• In some cases, this can add noticeable time and space overhead
Bad Example
Fonte: https://www.javacodegeeks.com/2012/06/demeter-law.html
Good Example