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.
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.