From: Ilmari Heikkinen Date: 2006-05-18T13:13:51+09:00 Subject: Re: Need help designing UI Hi, 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. In a DOM-like system: on clicking the button, it would bubble up aCloseWindow-event, which the Viewer would then catch and close thewindow. Pseudo-code: class Object def send_up(*args) process_up_event(*args) @parent.send_up(*args) if @parent endend close_button.on_click{ close_button.send_up(:close_window) }viewer.on_close_window{ exit } viewer << toolbartoolbar << close_button Ilmari