Greetings all :-)
I have a question regarding basic object creation and would be grateful for any guidance.
Let's say I have a class 'Vehicle' and from this class, I want to create 3 objects.
So, I might have:
Now, lets also say, that each 'vehicle' has a variable that is only useful for a particular Vehicle type. For example:
The car object needs:
The plane object needs:
And the bicycle object needs:
I could create 3 new classes that all extend from the Vehicle class.
So I could then do something like:
Where the classes Car, Plane & Bicycle, all extend the class Vehicle.
All of my specific variables could then of course go into their respective classes.
Is it excessive to create child classes simply to hold a few or boolean/ints?
What are the other options?
I could just put all three variables into the Vehicle class, but each object would have 2 unused and irrelevant variables (more, if I had to create more vehicles with specific and unique properties).
So is the first option the 'correct' way to do this or am I missing something!?
Thanks!