You can also look at some design patterns for guidance. Something like the
State pattern may be of use here. I wrote an article about it a while back
that you can see at
http://articles.techrepublic.com.com/5100-10878_11-6167539.html
On Tue, Sep 2, 2008 at 2:07 PM, Ronan Lucio <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> In the company I work we have an application where each client (record) can
> assume different status: active, inactive, blocked or partial blocked.
>
> The client form for record updates has a combo box where the user can
> select the client's status:
>
> <select name="status" id="status">
> <option value="A">Active</option>
> <option value="B">Blocked</option>
> <option value="P">Partial Blocked</option>
> <option value="I">Inactive</option>
> </select>
>
>
> OO thinking take me to the "Tell, don't ask" philosophy.
> So how do I need to for every setStatus() operation?
>
> Option 1: Set by code
> ======
>
> client.setStatus( form.status );
>
>
> Option 2: Special sets
> ======
>
> if ( form.status == 'A' ) {
> client.activate();
> } else if ( form.status == 'B' ) {
> client.block();
> } else if ( form.status == 'P' ) {
> client.partialBlock();
> } else if ( form.status == 'I' ) {
> client.deactivate();
> }
>
>
> The problem in the second approach is the it still have to keep some
> business logic and, it still needs to know the status codes.
>
> Using the first approach it still gives me the possibility to encapsulate
> the business logic inside it's set():
>
> function setStatus( status ) {
>
> if ( arguments.status == 'A' ) {
> client.activate();
> } else if ( arguments.status == 'B' ) {
> client.block();
> } else if ( arguments.status == 'P' ) {
> client.partialBlock();
> } else if ( arguments.status == 'I' ) {
> client.deactivate();
> }
>
> }
> }
>
>
> Any help would be appreciated,
> Ronan
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---