DEV Community

Cover image for Demeter’s Law: Don’t talk to strangers!

Demeter’s Law: Don’t talk to strangers!

Carlos Caballero on March 08, 2019

The Law of Demeter (LoD) or principle of least knowledge is a design guideline for developing software, particularly object-oriented programs — ...
Collapse
 
mariotk profile image
MarioTK • Edited

Dear Dr.Caballero,

I'm sorry to disturb you. I'm a computer science student

Demeter's law should simplify the dependency graph, reducing the overall coupling. The objective of this law is to improve encapsulation.

An object of class B (status information of A) should not return to A an object of class C (status information of B).

Right?

Thank you

Collapse
 
davidsusu profile image
Dávid Horváth

But "person.isZipCode(zipCode)" is (reverse) coupled to the consumer, isn't it? Even worse, we must also change House for getting zipcode or any other "random" information, such as "person.isLivingInCircle(geoCoords, maxDist)" or "person.isZipCodePrime()".

Collapse
 
matteobiagetti profile image
Matteo Biagetti

Great post!

The GitHub repo seem not reachable...

Collapse
 
carlillo profile image
Carlos Caballero

Hi Matteo!

I just fixed!

Thanks.

Collapse
 
abdurrahmaanj profile image
Abdur-Rahmaan Janhangeer

saved!

Collapse
 
carlillo profile image
Carlos Caballero

Thanks! Any question or comments are welcome! 😊

Collapse
 
manuelmolina97 profile image
Manuel

Great post! Keep it up!!

Collapse
 
carlillo profile image
Carlos Caballero

Thanks Manuel!

Collapse
 
olivermensahdev profile image
Oliver Mensah

Awesome Post.

Collapse
 
carlillo profile image
Carlos Caballero

Thanks Oliver 😊!