3 ms·
But doesn't that stright-up violate the Law of Demeter? http://en.wikipedia.org/wiki/Law_of_Demeter http://en.wikipedia.org/wiki/Law_of_Demeter
by DanHulton 18y ago
But doesn't that stright-up violate the Law of Demeter?
http://en.wikipedia.org/wiki/Law_of_Demeter http://en.wikipedia.org/wiki/Law_of_Demeter
- raganwald 18y agoGood question. That being said, I'm a long time Demeter Scofflaw...
- sysop073 18y agoI was just going to post that. If that's what he means it's the opposite of what you should usually do; in that example you're making register_with_irs() depend on the implementation of customer when it doesn't need to
- raganwald 18y agoAnd therein lies the trade-off. It may be that one day you need an address as well as an SSN to register an IRA. If you chose door A, you update the calling code to either pass both properties or pass a customer object. If you chose door B, you update the callee code to extract the address as well as the SSN. In one case we're arguing that the registration code shouldn't have to know how to work with a customer. In the other case we're arguing that code initiating a registration shouldn't have to know what the IRS wants from a customer. Seems like there's room for reasonable people to empty a bottle of single malt while debating the alternates.
- senorprogrammer 18y agoThat is indeed what I meant though of course it is not an absolute statement. As a general rule of thumb, inside your own web application, passing objects rather than raw data will lead to easier to read & debug code, quite likely at the risk of tighter coupling, you are correct. 'Course unless you're building a framework or library coupling should probably not be your main priority when building a web site. As for the Law of Demeter, like my list that too is a rule of thumb and not an absolute, requiring judgement calls.