![]() |
I'm sitting in a lecture right now, and I'm wondering - what's the point of Abstract Classes*?
* Ones that can not, or should never be created |
inherritance
so you can create 2 classes which share the same base. which is handy if you have virtual functions |
I use them all the time.
If you have a whole bunch of classes with properties or methods in common then put those properties or methods in an abstract base class. That base abstract class can have both abstract and non abstract methods. So when you derive from the base abstract class you can effectively force your derived classes to behave in a certain way… i.e. tell them which functions to override and which ones to not override… That’s how I use them anyway :whistle: |
If you translate them to the real world:
'Vehicle' could be an abstract class, since nowhere in the world would you find a 'vehicle' without some further specilisation. You'd find a 'Car', which would be a certain implementation of the abstract 'Vehicle' class or a 'Bike', or 'Airplane'. so you'd have Code:
class Car extends Vehicle EDIT: This way you can define some behaviour or properties of a class without actually specifying the implementation. E.g. all vehicle have a speed, some sort of propulsion mechanism etc. PS. You could also do this with an interface (say 'Drivable') but that's another way to model the world. |
Quote:
Code:
public void ChangeDirection(DirectionTypeEnum oDir) Abstract classes are cool... :max: |
The current time is 07:28 PM (GMT) |
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.