A
aaj
Hi all
I'm new to OOP and just getting to grips with inheritance.
Could anyone tell me if my understanding so far is correct.....?
If I have a base class, and then some derived classes with extra
functionality e.g.
Base Class : Watch Method SetTime
Derived Class : DigitalWatch Method ChangeBattery
Derived Class : AnalogWatch Method WindUp
is it acceptable to use the base class type to access the SetTime method in
all the watches and then in the same app to use the derived class type for
only digital watches
so in one place use
Watch CurrentWatch = (watch) AndysDigitalWatch; i.e. casting Digital watch
as a base type watch and only seeing the SetTime Method
and in another place use
DigitalWatch CurrentWatch = AndysDigitalWatch;
obviously it wouldn't be exactly like this, I'm thinking more when using
foreach on the base class object, bringing back all the watches derived from
the base class, but only the methods common to the base class and the
derived class.
So in summary, I guess what I'm asking is - is it acceptable to declare
types of Base class to do some functions common to all objects, and in the
same app, but in a different place, use the more specialised derived classes
thanks
Andy
I'm new to OOP and just getting to grips with inheritance.
Could anyone tell me if my understanding so far is correct.....?
If I have a base class, and then some derived classes with extra
functionality e.g.
Base Class : Watch Method SetTime
Derived Class : DigitalWatch Method ChangeBattery
Derived Class : AnalogWatch Method WindUp
is it acceptable to use the base class type to access the SetTime method in
all the watches and then in the same app to use the derived class type for
only digital watches
so in one place use
Watch CurrentWatch = (watch) AndysDigitalWatch; i.e. casting Digital watch
as a base type watch and only seeing the SetTime Method
and in another place use
DigitalWatch CurrentWatch = AndysDigitalWatch;
obviously it wouldn't be exactly like this, I'm thinking more when using
foreach on the base class object, bringing back all the watches derived from
the base class, but only the methods common to the base class and the
derived class.
So in summary, I guess what I'm asking is - is it acceptable to declare
types of Base class to do some functions common to all objects, and in the
same app, but in a different place, use the more specialised derived classes
thanks
Andy