2.4 How to do OOP inheritance?

In the child class you want to extend from the parent class, add option object(ParentName);

Here is an example

restart; 
module ODE() 
   option object; 
   local ode; 
 
   export set_ode::static:=proc(_self,ode,$) 
     _self:-ode :=ode; 
   end proc; 
 
  export get_ode::static:=proc(_self,$) 
     return _self:-ode; 
   end proc; 
end module; 
 
#create class/module which extends the above 
module second_order_ode() 
   option object(ODE); 
   export get_ode_order::static:=proc(_self,$) 
      return 2; 
   end proc; 
end module;
 

In the above second_order_ode inherits all local variables and functions in the ODE class and adds new proc. Use as follows

o:=Object(second_order_ode); #create an object  instance 
o:-set_ode(diff(y(x),x)=sin(x)); 
o:-get_ode(); 
o:-get_ode_order();
 

Note that the child class can not have its own variable with the same name as the parent class. This is limitation. in C++ for example, local variables in extended class overrides the same named variable in the parent class.

Even if the variable have different type, Maple will not allow overriding. For example, this will fail

restart; 
module ODE() 
   option object; 
   local ode; 
   local id::integer; 
 
   export set_ode::static:=proc(_self,ode,$) 
     print("Enter ode::set_ode"); 
     _self:-ode :=ode; 
   end proc; 
 
  export get_ode::static:=proc(_self,$) 
     return _self:-ode; 
   end proc; 
end module; 
 
module second_order_ode() 
   option object(ODE); 
   local id::string; 
   export get_ode_order::static:=proc(_self,$) 
      return 2; 
   end proc; 
end module; 
 
    Error, (in second_order_ode) local `id` is declared more than once
 

There might be a way to handle this, i.e. to somehow explicitly tell Maple to override parent class proc or variable name in the child. I do not know now. The above is using Maple 2021.1