loading words...

Jan 19, 2019 18:02:02

Law of Demeter

by @swizecteller | 203 words | 🐣 | 116💌

Swizec Teller

Current day streak: 0🐣
Total posts: 116💌
Total words: 32303 (129 pages 📄)

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



So the Law of Demeter was proposed by one Ian Holland in late 1987 and everything it says applies to modern JavaScript, React, Vue, or whatever programming.

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.

Originally published at twitter.com

contact: email - twitter / Terms / Privacy