From: Jim Weirich Date: 2005-03-23T13:33:56+09:00 Subject: Re: Any guides for good coding in Ruby? On Tuesday 22 March 2005 09:09 pm, Florian Gross wrote: > James Edward Gray II wrote: [... questionable OO design advice ...] > > I can't decide if it's just the example or the whole section, but this > > one just doesn't feel right to me. I would much rather have a class > > rendering itself (who better qualified?), then providing accessor like > > data for others to do it. Push, don't pull, right? > > I think this is related to double dispatch. There'll probably be a > Surface#draw that takes an object and calls #to_canvas on it. This way > both objects can handle part of the drawing contract by meeting in the > middle. This is often handled by the bridge pattern. The canvas object provides low level primitives (which can be reimplemented for different media) and the graphical objects draw themselves using the facilities provided by the canvas objects. The problem with that particular example is (1) it has little to do with API design (as it internally admits) and (2) the advice itself is questionable. Although there are times a pure data object makes sense, the advice is worded in a way that seems to recommend it. That kind of thought leads to anemic domain models that are all data and little behavior. -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)