54

Maintainability

Law of Demeter

Principle of Least Knowledge.

The article

If

An object that reaches through other objects' internals (`a.getB().getC().doThing()`) couples itself to the entire dependency chain, so a change anywhere along that chain ripples back and breaks it.

Then

Only call methods on your direct collaborators, your arguments, objects you create, and your own fields. If you are chaining getters, add a method to the object that owns the data.

Unless

Pragmatism over Dogmastrict application breeds forwarding and wrapper bloat

Source

Karl Lieberherr & Ian Holland, Assuring Good Style for Object-Oriented Programs (IEEE Software, 1989).

Go to the source

See also