http://qs321.pair.com?node_id=259332


in reply to Short Refactoring Tip: let the object do it for you

Id like to point out that this doesn't scale very well. Sure you have a valid point in a limited case, such as when there are only a few relevent states. But what happens when there are lots? Or the system is dynamic? Or if you want to say things like

if ($po->status->name =~ /^(sent|pending|waiting|procratinating|delaye +d)$/i) {

I'd rather write the above than call a bunch of methods, let alone write the methods in the first place. :-)

I thinks its unlikely I would write an object that require on a regular basis the double indirection like that. And if I did face a situation like my example above I'd probably do something more like

my $status=$pos->status; if ($status->is('Pending')) {} if ($status->in(qw(sent pending waitning procrastinating delayed)) { }

The issue here for me is that the use of 'Pending' isn't wrong, its the use of 'Pending' in such a way that I can't intercept that usage that is wrong. The subs above allow use to redefine the back end behaviour just as yours does, but its a lot more flexible an approach, while still providing us a way to block inapropriate checks. For instance $status->is('Pneding') should produce an error. Albeit a run time one. Oh well you cant have everything can you? :-)

Anyway, I use both styles as seems appropriate for the task at hand, often both at the same time even. :-)


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...