![]() |
#1 | ||
![]() ![]() ![]() ![]() ![]() ![]() |
![]() 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 |
||
![]() ![]() |
|
![]() |
#2 | ||
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
|
![]() inherritance
so you can create 2 classes which share the same base. which is handy if you have virtual functions
__________________
Flowing with the stream of life |
||
![]() ![]() |
|
![]() |
#3 | ||
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2005
Location: ,
Posts: 72
|
![]() 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: |
||
![]() ![]() |
|
![]() |
#4 | ||
![]() ![]() ![]() Join Date: Dec 2004
Location: Eindhoven, Netherlands
Posts: 1,508
|
![]() 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 class Bike 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. |
||
![]() ![]() |
|
![]() |
#5 | ||
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2005
Location: ,
Posts: 72
|
![]() Quote:
Code:
public void ChangeDirection(DirectionTypeEnum oDir) { * //Implementation here } Abstract classes are cool... |
||
![]() ![]() |
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Do You Like Idea Of Online Classes? | Rogue | Blah, blah, blah... | 14 | 30-11-2004 03:30 PM |
|
|
||
  |