in reply to Setting common object attributes
I have been creating an object model for a parking lot. My first attempt had 'Corolla' as a subclass of 'Toyota', as a Corolla was a more specific type of Toyota. However, I now realise that only the attributes are different; all the methods are the same. So, a 'Car' class would be enough:
Congratulations, you realized something important on your own!
But that means having a subclass, which is what I want to avoid. Is there a better way to set common attributes?
You could have an alternate constructor, say Car->new_corolla , although that will get boring soon ; by the third one you should be bored, realize the mistake -- having a database of cartypes/descriptions from which to set the defaults makes sense
But, FWIW (I realize its an exercise), a parking lot doesn't need to know drive_type/body_type/engine_cap, parking_lot only needs width/height/length/needs_towing :) and looking this up in a database to set the defaults makes sense
See also perlobj and lots of missing reference links here ... http://books.google.com/books?id=SXJ8x3q4TZ8C&pg=PA442&lpg=PA442&dq=object-oriented-design+parking+lot
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Setting common object attributes
by Anonymous Monk on Jul 18, 2013 at 03:10 UTC | |
|
Re^2: Setting common object attributes
by nevdka (Pilgrim) on Jul 18, 2013 at 23:00 UTC |