Re:Law of Demeter and immutability
by jessedhillon on Friday September 30, 2016 @01:11PM
(#12613726)
Demeter's Law is also called the Principle of Least Knowledge. The reason being that, if you have two dogs -- one robotic and one mammalian -- reading the angle of the second joint distal from the hip is going to walk a distinct path for each type, which requires some otherwise-dog-agnostic piece of code to now know about what types of dogs exist and how to traverse their skeletal chains.
IMO Law of Demeter is not chiefly about state protection -- it's a principle of good design which, when followed, unburdens developers from the cognitive load of keeping the entire universe in their heads. It forces them to think about what is the smallest amount of information this component needs in order to function.
I do agree with this one.
Re:Law of Demeter and immutability
by regularfry on Sunday October 02, 2016 @08:18AM
(#12622032)
It seems like you're trying to redefine what the LoD is because you think there's a more important principle it should refer to instead, or because you disagree with its original framing. That's not going to be a fruitful approach.
Also, your example isn't entirely valid as you mutate the objects' state.