Laws of Software Engineering · Principle
Principle
Law of Demeter
A piece of code should only talk to its immediate neighbours. It should not reach through them to talk to strangers.
How to use it. Count the dots. a.b.c.d() is a smell. If testing one thing means setting up seven others, you have probably broken this rule.
How it gets misused. Applied to data structures. The rule covers behaviour between objects. Reading values from a record is fine.
Related
-
Principle SOLID Five rules for designing object-oriented code: each class does one thing, code should be open to extension but closed to modification, subclasses should be substitutable, interfaces should be small, and code should depend on abstractions rather than specifics.
- Pattern Hexagonal Architecture (Ports and Adapters) Put the domain at the centre. Surround it with ports (the contracts the domain offers) and adapters (the code that connects ports to the outside world).
Clusters
- The Code Design cluster - How to write code that survives change.