$my_car->model("corvette");
That is against the OO-approach. Your car object is supposed to represent a real-life object (a car). You cannot change the model of a car. You can only get a new instance (a different car) for the new model.
How about this: A class CarPark which you can initialize from your file and query for Car objects.
my $park = new CarPark( filename => 'blah'); # this will read the file, and (unless the file # is too big or can change in between) save it into # an internal structure suitable for the lookups # you are going to do (probably hash keyed on car model) # so that you have to read it only once. my $car = $park->get("pinto"); print $car->horse_power; $car = $park->get("corvette"); # a new instance print $car->horse_power
In reply to Re: Advice on OO Program structure & organization
by Thilosophy
in thread Advice on OO Program structure & organization
by yoda54
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |