From: Tom Sawyer Date: 2002-07-21T04:19:39+09:00 Subject: Re: GUI's and the Rouge, Part II On Sat, 2002-07-20 at 12:25, Ned Konz wrote: > The main problem with this is that the data shouldn't have to know > about how it's going to be presented. > > When you want to display something on (say) a PDA, you might choose to > have different representations (shorter strings, no colors, etc.). > > Maybe the best strategy would be to have an intervening policy object > between the data and the widgets that determines how a given piece of > data would be presented in a particular kind of UI. thanks Ned, a good point. but thanks to ruby we can deal with this farily easily w/o having to resort to intervening objects by seperating parts of a class definition. just as one extends a class now one can create conditional extenstions dependent, say, on the platform. for exmaple: pda.rb: class MyClass def initialize super avar.extend RougeDeux::WidgetFactory(:Label) avar.style={:width=>10} end end pc.rb: class MyClass def initialize super avar.extend RougeDeux::WidgetFactory(:Label) avar.style={:width=>100} end end myapp.rb: class MyClass attr_accessor avar def initialize @avar = "" end end require pda.rb if $interface='PDA' require pc.rb if $interface='PC' so this is one approach. in a sense it is like an intervening object, only it's an intervening definition. (note: this does "confuscate" the object, but it does it in a clean, well seperated manner) i'm sure there are others ways. one thing i hadn't taken into account, that your post made me consider is the idea of stylesheets --convenient ways to set the properties of a large number of widgets at once. but i'm sure that would not be too difficult to factor in. ~transami -- ~transami _(")_ dobee dobee do... \v/ ^ ^