$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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.