Design Question

Discussion in 'Ruby' started by Zach Dennis, May 24, 2004.

  1. Zach Dennis

    Zach Dennis Guest

    I am having a small dillema. In a program I and a friend are writing I am
    proposing to have a Singleton Error/Status object that is updated with
    error/status information. For example (this code is nont tested and it is
    just a conceptual look):


    class StatusSingleton
    def setStatus( returnCode , message , obj=nil )
    @returnCode = returnCode
    @message = message
    @obj = obj
    end

    def getLastReturnCode
    return @returnCode
    end

    def getLastMessage
    return @message
    end
    end

    class MyObj
    def setTrue
    #A Big Error Occurs
    StatusSingleton.setStatus( "0x0080" , "Could not set true" );
    end
    end

    m = MyObj.new();
    if( !m.setTrue() ) then
    MyTkTextFieldWidget.setText( StatusSingleton.getLastMessage() )
    end



    Is my StatusSinglton overkill? I am trying to consolidate error information
    into one class. What do you think?

    Thanks,

    Zach

    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.684 / Virus Database: 446 - Release Date: 5/13/2004
     
    Zach Dennis, May 24, 2004
    #1
    1. Advertising

  2. Hello --

    "Zach Dennis" <> writes:

    > I am having a small dillema. In a program I and a friend are writing I am
    > proposing to have a Singleton Error/Status object that is updated with
    > error/status information. For example (this code is nont tested and it is
    > just a conceptual look):
    >
    >
    > class StatusSingleton
    > def setStatus( returnCode , message , obj=nil )
    > @returnCode = returnCode
    > @message = message
    > @obj = obj
    > end
    >
    > def getLastReturnCode
    > return @returnCode
    > end


    A quick hint: rather than use methods that start with "get" and "set"
    and just return instance variables, use the attr_* family of methods
    instead.

    >
    > def getLastMessage
    > return @message
    > end
    > end
    >
    > class MyObj
    > def setTrue
    > #A Big Error Occurs
    > StatusSingleton.setStatus( "0x0080" , "Could not set true" );
    > end
    > end
    >
    > m = MyObj.new();
    > if( !m.setTrue() ) then
    > MyTkTextFieldWidget.setText( StatusSingleton.getLastMessage() )
    > end
    >
    >
    >
    > Is my StatusSinglton overkill? I am trying to consolidate error information
    > into one class. What do you think?


    Another idea might be just to create your own Exception class:

    class SomeException < Exception; end

    and then raise and rescue accordingly:

    begin
    m = MyObject.new
    # do stuff that raises a SomeException on error
    rescue SomeException => e
    MyTkTextFieldWidget.set_text(e.message)
    end

    But there may be something that this doesn't give you that I'm not
    taking into account.


    David

    --
    David A. Black
     
    David Alan Black, May 24, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ZackS
    Replies:
    5
    Views:
    6,868
    Just an Illusion
    Jul 9, 2004
  2. SpamProof
    Replies:
    3
    Views:
    669
    SpamProof
    Dec 1, 2003
  3. dave
    Replies:
    5
    Views:
    616
    William Brogden
    Jul 17, 2004
  4. Tim Smith
    Replies:
    2
    Views:
    883
    Tim Smith
    Dec 15, 2004
  5. Bartholomew Simpson

    class design/ design pattern question

    Bartholomew Simpson, Jun 12, 2007, in forum: C++
    Replies:
    2
    Views:
    462
    Daniel T.
    Jun 12, 2007
Loading...

Share This Page