in reply to Short Refactoring Tip: let the object do it for you
You are on the right road, but it seems as if nobody has mentioned your solution is not good OO design:
BAD: if ($po->status->name eq 'Sent') ... ALMOST AS BAD: if ($po->can_send) ... GOOD: $po->send
You are breaking encapsulation in all but the last case. Getters are a design smell. They are just a way to make private data public.
Instead of asking objects questions, tell them to do things. The object will figure out how to do it.
Allen Holub says about this:
"Never ask an object for the information you need to do something; rather, ask the object that has the information to do the work for you."
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Short Refactoring Tip: let the object do it for you
by Ovid (Cardinal) on May 21, 2003 at 23:28 UTC | |
by mvc (Scribe) on May 22, 2003 at 11:38 UTC | |
Re: Re: Short Refactoring Tip: let the object do it for you
by dws (Chancellor) on May 22, 2003 at 03:33 UTC | |
by mvc (Scribe) on May 22, 2003 at 11:08 UTC | |
by dws (Chancellor) on May 22, 2003 at 18:46 UTC | |
by mvc (Scribe) on May 22, 2003 at 19:58 UTC | |
by Anonymous Monk on May 22, 2003 at 16:58 UTC |
In Section
Meditations