Today I learned about the Law of Demeter. A law of software architecture that's as old as me. A few months younger maybe. #200wordsTIL
Yes you too can learn a lot from principles 30 years old.
Your components should 👇
1. Have limited knowledge about other units
2. Only talk to their friends, no strangers allowed
3. Talk only to close immediate friends
You can apply this to functions, components, objects, everything really. The Law of Demeter a good law with many advantages.
Your program is more adaptable, easier to maintain, and easier to understand. Less coupling means less stuff you have to grok to fix a bug.
An example of formalizing this into a system are layered architectures. Your frontend and your backend don't know too much about each other. Your styles don't have intimate knowledge of your layout. Etc.
A downside of the Law of Demeter is that you might end up writing a lot of wrappers wrapping wrappers that wrap components that do the things.
So think of it as a code smell.