From: Robert Klemme Date: 2004-08-30T01:45:33+09:00 Subject: Re: Design advice "Carl Youngblood" schrieb im Newsbeitrag news:e5ed7b690408281742613218ff@mail.gmail.com... > I'm in the process of writing a ruby version of perl's Palm::PDB > family, which allows you to write and read Palm database (PDB) files > for a number of Palm OS applications like Phone Book, ToDo, Datebook > etc. > > FYI, documentation of Palm::PDB is here: > > http://aspn.activestate.com/ASPN/CodeDoc/p5-Palm/Palm/PDB.html > > PDB files have a generic header format and hold one or more records, > each of which is in an application-specific format. > > The approach of perl's Palm::PDB is to create an abstract record > handler class and create a new child of the record handler class for > each application. The Palm::PDB class calls the record-handling > functions of whatever handler the programmer includes. > > I'm debating between this approach, and simply creating a parent PDB > class with empty functions for handling records and creating > descendents of this parent class with filled-in methods for record > handling as well as application-specific methods. I'd follow the perl pattern: If I understood correctly, the base class has all the functionality that's common to all applications (i.e. opening, closing, reading the header and generic record reading methods). Sub classes then need to add only the application specific stuff. (Maybe #each for each record or somthing similar; in that case the base class cound mixin Enumerable.) An alternative would be to use delegation, i.e. have a single class that does all the low level stuff and a class for each application that provides application specific code and interface. But I rather tend to the first approach as it seems to me that some of the base class functions will be invoked by clients (i.e. reading header info or so) - that makes delegation ugly because then you'll have some / a lot methods that simply delegate. Additional remark: this might lend to a transaction like behavior with a class method open() that yields a sub class instance (if it's possible to determine the sub class from all infos provided by open). module PDB class DB def self.open(file, mode) db = ( case file when /.dat/ DbDatabase .... ).new(file, mode) begin yield db ensure db.close end end end end Then PDB::DB.open("foo") do |db| db.each do |record| p record end end Kind regards robert