Question: provide way to override variable and method in base class by classes that extend base class?

Maple Object model is somewhat limited.  One of the main reasons to use OOP is to be able to extend base class, and override methods in base class by new methods if needed.

This is described in  https://en.wikipedia.org/wiki/Method_overriding

Method overriding, in object-oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. It allows for a specific type of polymorphism (subtyping). The implementation in the subclass overrides (replaces) the implementation in the superclass by providing a method that has same name, same parameters or signature, and same return type as the method in the parent class.[1] The version of a method that is executed will be determined by the object that is used to invoke it. If an object of a parent class is used to invoke the method, then the version in the parent class will be executed, but if an object of the subclass is used to invoke the method, then the version in the child class will be executed.[2] Some languages allow a programmer to prevent a method from being overridden.

Maple does not allow the extending class to override variables or methods in the base class. Even if the type of the variable or the sigature of the proc is different as long as the name is the same.

This makes it hard to override base class implementation and to do type extension.

Here is a toy example

restart;

 animal:=module()
   option object;
   export data1;

   export move::static:=proc(_self,$)
      print("In Animal class. moving ....");
   end proc;  
end module;
 
#create class/module which extends the above
dog:=module()
   option object(animal);
   export move::static:=proc(_self,$)
      print("In dog class. moving ....");
   end proc;  
end module;

Error, (in dog) export `move` is declared more than onc

All computer languages that supports OOP that I know about supports overriding, The above web page lists some. 

Ada,  C#C++, DelphiEiffel, Java, Kotlin, Python, Ruby

A workaround, is if such name conflict occurs, is to come up with new name. So the above example becomes


dog:=module()
   option object(animal);
   export move_the_dog::static:=proc(_self,$)
      print("In dog class. moving ....");
   end proc;  
end module;

And now Maple does not complain. But the whole point of type extension is to override the base class implementation, and not add a new implementation while keeping the base class one there.

Is there a way to do this in Maple? if not in current version, are there plans to add this to future Maple versions?

Please Wait...