Skip to content

Commit 40d929d

Browse files
Links for Law of Demeter, including link to @erikdietrich 's post
1 parent 41054db commit 40d929d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

design-patterns/law-of-demeter.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Law of Demeter
22

3-
## [Krzysztof Grzybek](https://github.com/krzysztof-grzybek)
3+
* [Law of Demeter - Wikipedia](https://en.wikipedia.org/wiki/Law_of_Demeter)
4+
* [Law of Demeter - WikiWikiWeb](https://wiki.c2.com/?LawOfDemeter)
5+
* [Introducing Demeter and its Laws](http://www.bradapp.net/docs/demeter-intro.html)
46

7+
## Mnemonic for the Law of Demeter
8+
The post [Visualization Mnemonics for Software Principles](http://www.daedtech.com/visualization-mnemonics-for-software-principles) by [Erik Dietrich](https://github.com/erikdietrich) provides a very effective trick to understand (and never forget anymore) what the Law of Demeter is. An Italian translation is available [here](https://github.com/arialdomartini/mnemonics/blob/law-of-demeter/README-italian.md).
9+
10+
## Code Example
11+
An example of code violating the Law of Demeter is provided by [Krzysztof Grzybek](https://github.com/krzysztof-grzybek)
512

6-
Code violating The Law of Demeter:
713
```javascript
814
class Plane {
915
constructor(crew) {
@@ -27,6 +33,7 @@ class Pilot {
2733
}
2834
}
2935
```
36+
3037
It's bad, because it creates tight coupling between objects - they are dependent on internal structure of other objects.
3138

3239
Fixed code:
@@ -46,4 +53,3 @@ class Crew {
4653
return this.pilot.getName();
4754
}
4855
}
49-

0 commit comments

Comments
 (0)