DEV Community

Cover image for Decoding the Law of Demeter through Real-World Example
Thomas Heniart
Thomas Heniart

Posted on

Decoding the Law of Demeter through Real-World Example

Have you ever heard of the Law of Demeter? Do you know if you are violating it?

Let's dive into a real-world example: I am looking for "Test Driven Development By Example," and I know that one of my
friends (let's call him John) told me about one of his other friends (whom I don't know yet) who found a second-hand
example.
I would directly ask John to inquire where he bought it.

It would be counterproductive to ask John to meet his friend and then ask him about it.

My only interest is in John being able to find the information I am looking for.
He may even already know the answer, but I need to know.

If you are familiar with OOP, it should ring a bell and make you think about one of the most fundamental rules of OOP:
Tell, don't ask
.


Stay tuned for more insights! Free to follow me on this platform
and LinkedIn. I share insights every week about software
design, OOP practices, and some personal project discoveries! 💻🏄

Top comments (1)

Collapse
 
salu_bhai_84f2aac2ebfd3a7 profile image
Salu Bhai

Decoding the Law of Demeter helps us understand how to reduce dependencies in programming. A real-world example makes it clearer and easier to apply. Just like when using an usa apostille services, you want to keep things simple and direct. By following this principle, developers can create cleaner and more maintainable code, leading to better software overall.