C
craigkenisston
Hi,
I will use an example to do a simplified description of my problem,
please don't laugh.
I just "believe" I would have to use either interface or abstract
classes, but I've not ever write an interface, though I know the basis
of
interfaces.
So, let's say I have a class "RoboDriver", which is a robot which
dedicated task is to drive vehicles.
So, I will have an "Vehicle" class, too.
In order for do the proper programming of RoboDriver, I need that
vehicle provides some information, like type of vehicle (car,
motorcycle,
truck), also I would need the instances to be able to tell me whether
the vehicle is automatic or standard transmition, in case of car or
trucks,
then, to ask the number of gears.
If I write an IVehicle interface, how do I manage to know the inherited
classes type ? I mean, I can't enumerate all types of vehicles, nor I
will
know if I new type is invented but due similarities (and compatibility)
my RoboDriver class will be still able to know how to handle it.
Also, how do I ask for the optional properties ? I mean, let's say I
will have to ask about the transmission type only for certain vehicle
types,
I don't find elegant to have properties like "bool
IsManualTransmision", because, what if the implementor hardcode a
"true" return and then when I
call PutGear1, I get a notimplemented exception ?
Do you get my idea ? Which is the more appropiate way to go with this ?
Any comments of any kind are welcome.
I will use an example to do a simplified description of my problem,
please don't laugh.
I just "believe" I would have to use either interface or abstract
classes, but I've not ever write an interface, though I know the basis
of
interfaces.
So, let's say I have a class "RoboDriver", which is a robot which
dedicated task is to drive vehicles.
So, I will have an "Vehicle" class, too.
In order for do the proper programming of RoboDriver, I need that
vehicle provides some information, like type of vehicle (car,
motorcycle,
truck), also I would need the instances to be able to tell me whether
the vehicle is automatic or standard transmition, in case of car or
trucks,
then, to ask the number of gears.
If I write an IVehicle interface, how do I manage to know the inherited
classes type ? I mean, I can't enumerate all types of vehicles, nor I
will
know if I new type is invented but due similarities (and compatibility)
my RoboDriver class will be still able to know how to handle it.
Also, how do I ask for the optional properties ? I mean, let's say I
will have to ask about the transmission type only for certain vehicle
types,
I don't find elegant to have properties like "bool
IsManualTransmision", because, what if the implementor hardcode a
"true" return and then when I
call PutGear1, I get a notimplemented exception ?
Do you get my idea ? Which is the more appropiate way to go with this ?
Any comments of any kind are welcome.