From: Xavier Date: 2006-05-18T15:01:36+09:00 Subject: Re: Need help designing UI Scott L Holmes wrote: > Hi, > > I'm working on a user interface and I'm hoping I can get some > feedback/advice. I have 3 main classes: Viewer, Toolbar and > ToolbarButton. Given that an instance of Viewer has an instance of > Toolbar and that Toolbar has a collection of ToolbarButtons, I'm trying > to decide how I want to implement the workflow for the "Close" process. > The creation of all these instances is all rather "pretty" at the moment > but no instances really "knows" or cares about the other. (parts is > parts!) > > So, consider when the user clicks a "close window" ToolbarButton. > Somehow the Viewer must be informed that its time to close the window. > > For some reason, I'm trying to avoid keeping a reference to the Viewer > in the button (like with a call back). I'm hoping for a somewhat more > interesting design. I've tried a variety of things over the years but > I'm curious what others have tried, got working and generally like. > > Any comments would be greatly appreciated. > > Scott Investigate a listener/dispatcher pattern, as used by the Java Swing Framework. Basically, have a control class (MainProgram) register itself as a 'click listener' on the close button (this is done with interfaces in Java - obviously not necessary for ruby code). That way, the control flow of the program is abstracted outside of your specific UI components. If every toolbar has a close button, then it may be better to have the toolbar register itself as a click listener on the close button, and then reposting this as a close event. - Xavier -- Posted via http://www.ruby-forum.com/.