|
-
Sep 18th, 2007, 12:45 PM
#1
Thread Starter
PowerPoster
abstract/base class Q's
I'm kind of in a different and wierd mindset, so I apologise.
What is the point on having abstract/inheritence? Example, we can have a base class called "vehicle", has methods like "drive()" "stop()" etc.... and classes "Car", "Truck", "Van", "Bus" can derrive from base class "vehicle". Thats all very well, but really what would be the point in that?
why should we also sometimes call a base method? Would that only happen if we override a method which has been declared as a virtual method in the base class?
Sorry for the silly Q, im just soaked up in something and perhaps thinking way too hard into it.
-
Sep 18th, 2007, 07:12 PM
#2
Re: abstract/base class Q's
The point of an abstract class is that you ensure that all derived types can do a certain thing but you don't care how they do it. An abstract base class is generally like a combination of a regular base class and an interface. You get the ability to implement some members like a regular base class, but you also get the ability to force each derived class to implement certain behaviour to ensure a standard interface to possibly disparate functionality.
Yes, you call a base method when you still wnat to invoke the "standard" beahviour but also add some custom behaviour of your own. An example is overriding the OnPaint method in a control. You add some code of your own to do some custom drawing but you also invoke the base method so that the control's Paint event is raised.
Last edited by jmcilhinney; Sep 18th, 2007 at 07:28 PM.
-
Sep 18th, 2007, 09:01 PM
#3
Thread Starter
PowerPoster
Re: abstract/base class Q's
thanks, much appreciated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|