--- Matthew Simon Cavalletto <[EMAIL PROTECTED]> wrote: > More generally, I would side with Aristotle's position against > mutator > chaining, set forth at <http://perlmonks.org/index.pl/417872>, > particularly in cases which seem to mix mutators with sub-object > accessors -- are you really calling get_date() on the result of > replace_content(), as shown in the "plain" example above? Yikes!
Chained mutators spanning classes is truly horrible style that leads to code that is difficult to maintain. However, that's just a violation of the Law of Demeter (http://c2.com/cgi/wiki?LawOfDemeter) and has nothing specific to do with chained mutators. Attacking chained mutators because some people choose to violate this Law seems silly. If they stop violating a well-known software design issue, one of the biggest (and false) objections to chained mutators goes away. Aristotle's argument, to my mind, has a serious flaw: if you don't like chained mutators, don't use them. If my methods return $self, there is nothing stopping you from *not* chaining. Further, providing a bulk 'setter' has a similar flaw to the Law of Demeter argument: $o->set( foo => 'bar', baz => 'quux', ); In short, whether or not this is a good interface has nothing to do with whether or not chained mutators are a good idea. Of course, we can argue that chained mutators are suboptimal because there's a better option (the bulk setter), but the bulk setter has issues of its own (http://www.perlmonks.org/?node_id=418166) so until I hear something more persuasive (and I'm all ears) I merely view this as a matter of style. The primary problem I see with chained mutators being the (occasional) need to return to Null object and overload its boolean value. This is slow in Perl, but if the Null object is not a common case then this is probably not that much of an issue. Cheers, Ovid ===== Silence is Evil http://users.easystreet.com/ovid/philosophy/decency.html Ovid http://www.perlmonks.org/index.pl?node_id=17000 Web Programming with Perl http://users.easystreet.com/ovid/cgi_course/ _______________________________________________ sw-design mailing list [email protected] http://metaperl.com/cgi-bin/mailman/listinfo/sw-design
