From: Tony Headford Date: 2006-02-14T06:34:35+09:00 Subject: Re: OO Design Advice Jeff Cohen wrote: > unknown wrote: > >>I'm trying to master the more subtle elements of Rubyish OO design, and >>am having trouble with the following aspect: >> >>I have a complicated, nested, value object ( eg >>order.customer.address.zipcode, or order.product[0].description). >> >>This object needs to be sent to various feeds (usually XML, sometimes >>REST / HTTP form ) run by other companies. > > > I say, you should definitely abstract away the "rendering" of the data > from the data model itself. I would recommend reading up a bit on the > "strategy" design pattern, but basically the idea is to take something > that varies (i.e. your feed formatting) and separate it from the things > that don't vary (your data model). > > So to render your data for a particular feed, you just instantatiate the > particular renderer that you need for that feed, pass it an instance of > your data, and then let the renderer worry about all of the formatting. > > Make sense? I can elaborate more if that would be helpful. > > Jeff > www.softiesonrails.com > In my experience what Jeff suggests is the right OO way to go. The model does not need to know how to render itself for specific feeds, that would be a function of the feeds themselves or an adapter class. cheers, Tone.