The Law of Demeter: Explained To Anyone (OOP)

What it mean? 🤔

Well, we know that objects hide their data and expose functions to interact with the outside. But sometimes we don’t keep it

Why is bad coding practice? ❌

Because we are breaking one principal essence of Object-oriented-programing, what is hide our data. In this case we showed the object’s innards to module which is manipulating the object.

The system maintenance will be more difficult

Let’s imagine that we want to do refactor to our code, specifically to object “Owner

How to fix this? 🛠

Instead of digging deeply the object in the call, we might do that the object we call return to us all the data we want 😁

This law also have another phrase that say

Conclusion 😉

The Law of Demeter” is useful to maintain of system software and to protect the principles of Object-oriented-programming. I invite you to use it and read the book “Clean Code”, an amazing book ❤.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store