T
Tony Johansson
Hello!!
Assume we have one base class called Vehicle and two derived classes called
Car and Bus.
I would be able to call method getName on an object of class Car or Bus and
return back the name that is set for this class. Asking getName on an object
of class Vehicle is of no interest. Assume we have an attribute called name
of type string.
Now to my question do you think it's right to put the name attribute in each
of class Car and Bus. I think so.
I think putting the name attribute in class Vehicle is wrong because the
name is different in class Car and Bus.
The name attribute is set in the c-tor for class Car and Bus.
This getName is made pure virtual so polymorfism can be used to call the
right getName depending of the object type
I'm I right in my thoughts.
Many thanks
//Tony
Assume we have one base class called Vehicle and two derived classes called
Car and Bus.
I would be able to call method getName on an object of class Car or Bus and
return back the name that is set for this class. Asking getName on an object
of class Vehicle is of no interest. Assume we have an attribute called name
of type string.
Now to my question do you think it's right to put the name attribute in each
of class Car and Bus. I think so.
I think putting the name attribute in class Vehicle is wrong because the
name is different in class Car and Bus.
The name attribute is set in the c-tor for class Car and Bus.
This getName is made pure virtual so polymorfism can be used to call the
right getName depending of the object type
I'm I right in my thoughts.
Many thanks
//Tony