From: David Alan Black Date: 2004-05-25T05:53:45+09:00 Subject: Re: Design Question 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 dblack@wobblini.net