dmitri wrote: |
Quote: | Base classes should only have functions that are general for all child classes |
correct but only partially.
What if I need OBJECT to be parent for FLYINGOBJECT, DRIVINGOBJECT, SWIMMINGOBJECT and DIGGINGOBJECT?
They all are supposed to have MOVE and all their children will have DRAW. Why not to have the two in their parent?
What if my system manages such objects and ask them to move and to draw? |
Well if they are all to have the function MOVE, and MOVE can not be implemented on OBJECT then it is declared abstract and MUST be implemented on FLYING,DRIVING,SWIMMING,DIGGINOBJECT.
If you mean that subclasses of FLYING,DRIVING,SWIMMING,DIGGINOBJECT will need DRAW, then you create an interface for the DRAW method and let the child classes implement the interface.
This is a basic problem with multiple inheritence in OOP.
Please not in the article that I included the URL to you will find this text.
Because the class is abstract, an instance of it can never be created (remember, it is only a partial implementation). Instead a child class must be created using inheritance and implement the fire method in itself. Failure to do so will result in a fatal error. Listing 2 shows a child class being created from the Abstract Weapon class.
So if you do not implement all abstract functions on child classes you will get a FATAL error. If you had a compile like feature, then you will be able to avoid this by "compiling" your code.