On Wednesday 30 April 2008, Rick DeNatale wrote:
On Tue, Apr 29, 2008 at 4:26 PM, Michael S.
[email protected] wrote:
Hmm, I sniff the code smell of a violation of the /law|strong
suggestion/ of Demeter here.
I don’t. That law doesn’t say only a single dot is allowed, does it?
Apart from being called a law, I’d like to see exactly what improvement
following that rule would effect in this particular case.
In my rails code I very rarely have assignments like the one above. What
I do have is views and particularly forms where I show and edit objects
and related objects, such as a person and their address. Partials lend
themselves to this and in such a case, I want to pass a valid object,
say an address, into the partial. In a sense I’m even following the Law
of Demeter in that way. Anyway, whenever person.address gets passed
into the address partial, I want it to be initialized with an
appropriate address object.
Better to define a city= method on Person (if this is what you really
want) which hides the implementation.
Even if I did that – which I won’t without positive indication --, it
would not remove the original problem. As a negative indication I’d
like to point out that adding #city=, #zip= etc. to Person dilutes the
responsibility of that model class. These attributes belong on an
Address model class. Now, if we take presenters into consideration,
there I’d be inclined to put all relevant accessors directly on the
presenter. But at any rate, that wouldn’t touch the original issue.