From: John Wilger Date: 2004-11-14T01:46:40+09:00 Subject: Re: advice for a class implementation? ( ugh, long... ) On Sat, 13 Nov 2004 10:20:43 +0900, Corey wrote: > Though the various backends/datastores ( QuoteCollection::#{persistence} ) > won't share any actual implementation - I _do_ want to ensure that they will > all share the same _interface_... I want them all to have the same public > methods > This is why I had the notion of a base class for QuoteCollection. I guess > there is no way in ruby for me to formally enforce an "Interface" that all > QuoteCollection::#{persistence} classes must share. > > That being said, in response to an earlier post of mine, it was suggested > that I do things in the ruby-way rather than try too hard to bring old habits > from other languages. I totally agree with that advice - my aim here is to > understand/learn the ruby idioms. The most "transparent" way of doing things that I can think of that would ensure the same interface across all of the implimentations would be to have a single QuoteCollection class that would be used no matter what the actual backend was (which would ensure that you are providing the same interface. Then you could define a configuration file (in YAML?) that would specify which backend to use (and any necessary meta-data about the backend, i.e, login info). The implimentation details for the various backends could be defined inside modules, and the QuoteCollection class could dynamically include the appropriate module depending on the configuration setting. -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don't know," Alice answered. "Then," said the cat, "it doesn't matter." - Lewis Carrol, Alice in Wonderland