News for hackers. Stuff that matters.
Re:Law of Demeter and immutability by Koshkin on Friday September 30, 2016 @03:40PM (#12614756)
This "law" sounds like a reasonable idea, at first, but if you think about it for a few seconds, you'll realize that it makes little, if any, sense (at least, when taken out of some specific context). As the designer of the class, often neither you can possibly anticipate all the ways in which objects of the classes involved will be used, nor would you want to re-expose all (or some of) the APIs provided by the "subordinate" classes.
Re:Law of Demeter and immutability by coldtea on Friday September 30, 2016 @04:07PM (#12614949)
>As the designer of the class, often neither you can possibly anticipate all the ways in which objects of the classes involved will be used

That's why you subclass -- or compose. The subclass can use them in other ways.

The problem with what you say, that you can't "possibly anticipate all the ways in which objects of the classes involved will be used" is that if you let that happen, then you have to forever support the different ways by which they are used -- and you can't change your implementation internally, make it more efficient etc, because different external code uses various internal details of it.

Re:Law of Demeter and immutability by regularfry on Sunday October 02, 2016 @08:16AM (#12622022)
It's a law as in "law of nature" not "law of the land". Things which follow LoD can be observed to have certain properties.
Re:Law of Demeter and immutability by paulddraper on Friday September 30, 2016 @03:58PM (#12614882)
I've always thought this to.

Some say the law is actually a guideline.

I say it's one extreme of a spectrum, and we would do well to aim for the middle.