Single inheritence means a class can only extend one other class. Ex. Circle extends Shape. Multiple inheritence means that a class could extend multiple classes. The wiki article for
multiple inheritance gives an example of a
StudentMusician class which inherits "from a class named
Person, a class named
Musician, and a class named
Worker". The wiki also mentions a major "obstacle" to multiple inheritance - the
Diamond problem. Truthfully, I'd rather not have to learn how to implement multiple inheritance, if it can be advoided (honestly, it might be beyond my abilities). I brought up the question, so if there was a demand, I would give it a shot, but to implement it "just because" is too much work. Additionally, multiple inheritance is inheritently less efficient.
Actually, I revoke my question - I do that a lot, huh...

. If the need arises, I'm sure I can modify the code and still provide backward compatability. I mean, structurely, they are the same. The difficulty is how to "merge" the classes (in the case of the diamond problem), how to "partition the classes" (to allow the getters / setters to work as expected - without modification to the getters and setters - instead, do the work in the Class_getValue function). So, it sounds like multiple inheritance would be "nice", but isn't needed. So, for simplicity, I'll do single inheritance, and I'll figure something out, if / when multiple inheritance is needed.
One of the major worries I have, is making sure the getters and setters work correctly for inheritance.
Ex. if Shape had a color value (in index "b1"), and Circle extended Shape, then Shape_getColor(myCircle) should function correctly (returning the color). Also, suppose that Circle put the radius value in its "b1" space, the Class_getValue function (after modification) needs to function, as expected, in the following cases.
Code:
;returns the Color of myShape
Shape_getColor(myShape)
;returns the Color of myCircle
;Circle_getColor would be an "alias" for Shape_getColor - see declaration below
Circle_getColor(myCircle)
;returns the Color of myCircle
Shape_getColor(myCircle)
;returns the radius for the Circle object
Circle_getRadius(myCircle)
/*
Class functions
*/
Shape_getColor(ShapeObject)
{
return Class_getString(ShapeObject, "b1")
}
;"alias" for Shape_getColor
Circle_getColor(CircleObject)
{
return Shape_getColor(CircleObject)
}
Circle_getRadius(CircleObject)
{
;type is "uint"
return Class_getValue(CircleObject, "b1")
}
This would allow a Class to extend another Class without worrying about changes in the base class. Class_getValue would sort the details concerning which index to use, and it would adjust by using the built-in and user-defined size of the base class and "partition" the object - via a wrapped call to the Class_getBuiltInSize and Class_getUserDefinedSize (to determine the size of the base class object).
In the "new" function, the allocation would include both the built-in size and user-defined size of the Class designed class and its base class (if any). The base class values would be initialized via the getters and setters (or via Class_setValue, directly).
Class functions in the base class could be implemented in one of two ways - "virtual" and "non-virtual". See the wiki page for
virtual function for in-depth details.
Non-virtual would mean that
BaseClass_myFunction(InheritedClassObject, args...) and
BaseClass_myFunction(BaseClassObject, args...) would both evaluate
BaseClass_myFunction. The function calls would function correctly, since the values (the getters and setters) would be as expected (see above example).
Virtual functions would mean that
BaseClass_myFunction(InheritedClassObject, args...) would actually call (if it exists)
InheritedClass_myFunction(InheritedClassObject, args...). The setup for virtual functions would be similar to an interface function (with some slight modifications). I will provide a template function that can be easily modified for all your Virtual function needs.
Functions would default to non-virtual (opt-in virtual), because it would require a little "extra" in the code to provide this functionality. It won't be long or complicated (it will call a Class library function which will handle the details), but it is required. Thus, virtual will be opt-in (like C++), not the default - like java.
_________________
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the
Class Library. Check out
my scripts.