From: Ryan Leavengood Date: 2006-05-18T01:29:06+09:00 Subject: Re: Need help designing UI Over the years I'm sure there has been invented countless ways of doing what you are asking, but I am personally most experienced with the GUI system on BeOS, which I think is a very nice design. Essentially all communication between various parts of the system (from the OS to applications and back, from applications to their windows and back, from windows to the GUI components and back) is done via messages. A looper class is used to loop over messages coming in and then the handling of these messages are delegated to a handler class. On BeOS frequently the looper and handler are the same class. Messages are handled first by their direct recipient (for example a mouse down would be handled first by the component being clicked on.) If the message cannot be handled by that recipient, it is passed up the inheritance hierarchy until it is handled. Usually messages that are used within an application itself are targeted directly to the window, and then the window can delegate to the appropriate component. So for you example, the "Close Window" toolbar button would have a message with an associated CLOSE command constant, with the target of the message being the window. When the button is clicked, the CLOSE message will be sent to the window and the handling of that message will close the window (of course.) The nice thing about this is that the CLOSE message could be used from other places without having to change how it is handled within the window. Ryan On 5/17/06, 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