in reply to Advice on OO Program structure & organization
Have a Class method (not a instance method) called (say) loadFrom(), that takes a filename, and returns an array of instances.
Have another Class method (say) findMatching(), that takes a reference to that array and a partially completed instance of that class, and returns one or more matching instances from the array.
use Car; my @cars = Car->loadFrom( 'cars.dat' ); my $partial = Car->new( horsepower => 200 ); my @matches = Car->findMatching( \@cars, $partial ); print $_->details for @matches;
If you move your data from a flatfile to a DB, you pass a DB handle (or credentials) to loadFrom() and everything else still works.
As you add attributes to your class, the search code continues to know how to compare your instances, and your instantiator knows how to construct (partial) instances. The internals can change as needed, with the external inteface remaining the same, except where you need deal with new attributes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Advice on OO Program structure & organization
by exussum0 (Vicar) on Dec 11, 2004 at 13:42 UTC |