Properties validation in subclass with multiple superclass but same ancestor
hello everyone,
I have a problem: I’m trying to build a (quite complex) super/subclassing tree for a project, but I’m stuck before MATLAB failed at instanciating an object deriving from multiple classes but that at the end derive from the same root object, and in this root object I defined an abstract property, with some validators, that should be define in the concrete object.
According to this page, it should works, but it does NOT work in my case (MATLAB 2024a; I plan to migrate to newer versions soon).
Minimum Workin Example (MWE) completely unrelated to my project:
let’s suppose that i have to model several vehicles, so I can create a superclass called "vehicles" with some properties, including the minimum number of staff required to run it:
classdef vehicle < handle
properties (Abstract, Constant)
required_staff (1,1) {mustBeNumeric}
end
methods
function obj = vehicle()
end
end
end
Now, we can specialize the "vehicle" in several ways and multiple times, for example by creating a "landVehicle" class, a "bike" class (extending "landVehicle"), an "electricalVehicle" (all these classes may define something more, but for this MWE we can have them "empty" and it will not change) and finally the "EBike9000" that is an electrical bike.
Code for the "bike" class (the other mid-classes are similar):
classdef bike < landVehicle
end
Code for the "EBike9000" concrete class:
classdef EBike9000 < bike & electricalVehicle
properties (Constant)
required_staff = 1
end
end
Now, the only definition and validation for the required_staff property is in the root "vehicle" class. The middle class never mention it, however, when I tried to instantiate an EBike9000 object, matlab complain with:
Error using EBike9000
Class ‘electricalVehicle’ and class ‘bike’ both define validation for
Abstract property ‘required_staff’. When inheriting property validation,
only one superclass can define validation for property ‘required_staff’.
However, this validator IS the same since it belong to the same superclass, so it should NOT be a problem for MATLAB to validate it (as also stated in the page I linked at the beginning).
So, what’s going on? is this a bug, or it’s me that I’m missing something? Ideas for some workarounds (except including a set.required_staff method which on all the possible vehicles around)?hello everyone,
I have a problem: I’m trying to build a (quite complex) super/subclassing tree for a project, but I’m stuck before MATLAB failed at instanciating an object deriving from multiple classes but that at the end derive from the same root object, and in this root object I defined an abstract property, with some validators, that should be define in the concrete object.
According to this page, it should works, but it does NOT work in my case (MATLAB 2024a; I plan to migrate to newer versions soon).
Minimum Workin Example (MWE) completely unrelated to my project:
let’s suppose that i have to model several vehicles, so I can create a superclass called "vehicles" with some properties, including the minimum number of staff required to run it:
classdef vehicle < handle
properties (Abstract, Constant)
required_staff (1,1) {mustBeNumeric}
end
methods
function obj = vehicle()
end
end
end
Now, we can specialize the "vehicle" in several ways and multiple times, for example by creating a "landVehicle" class, a "bike" class (extending "landVehicle"), an "electricalVehicle" (all these classes may define something more, but for this MWE we can have them "empty" and it will not change) and finally the "EBike9000" that is an electrical bike.
Code for the "bike" class (the other mid-classes are similar):
classdef bike < landVehicle
end
Code for the "EBike9000" concrete class:
classdef EBike9000 < bike & electricalVehicle
properties (Constant)
required_staff = 1
end
end
Now, the only definition and validation for the required_staff property is in the root "vehicle" class. The middle class never mention it, however, when I tried to instantiate an EBike9000 object, matlab complain with:
Error using EBike9000
Class ‘electricalVehicle’ and class ‘bike’ both define validation for
Abstract property ‘required_staff’. When inheriting property validation,
only one superclass can define validation for property ‘required_staff’.
However, this validator IS the same since it belong to the same superclass, so it should NOT be a problem for MATLAB to validate it (as also stated in the page I linked at the beginning).
So, what’s going on? is this a bug, or it’s me that I’m missing something? Ideas for some workarounds (except including a set.required_staff method which on all the possible vehicles around)? hello everyone,
I have a problem: I’m trying to build a (quite complex) super/subclassing tree for a project, but I’m stuck before MATLAB failed at instanciating an object deriving from multiple classes but that at the end derive from the same root object, and in this root object I defined an abstract property, with some validators, that should be define in the concrete object.
According to this page, it should works, but it does NOT work in my case (MATLAB 2024a; I plan to migrate to newer versions soon).
Minimum Workin Example (MWE) completely unrelated to my project:
let’s suppose that i have to model several vehicles, so I can create a superclass called "vehicles" with some properties, including the minimum number of staff required to run it:
classdef vehicle < handle
properties (Abstract, Constant)
required_staff (1,1) {mustBeNumeric}
end
methods
function obj = vehicle()
end
end
end
Now, we can specialize the "vehicle" in several ways and multiple times, for example by creating a "landVehicle" class, a "bike" class (extending "landVehicle"), an "electricalVehicle" (all these classes may define something more, but for this MWE we can have them "empty" and it will not change) and finally the "EBike9000" that is an electrical bike.
Code for the "bike" class (the other mid-classes are similar):
classdef bike < landVehicle
end
Code for the "EBike9000" concrete class:
classdef EBike9000 < bike & electricalVehicle
properties (Constant)
required_staff = 1
end
end
Now, the only definition and validation for the required_staff property is in the root "vehicle" class. The middle class never mention it, however, when I tried to instantiate an EBike9000 object, matlab complain with:
Error using EBike9000
Class ‘electricalVehicle’ and class ‘bike’ both define validation for
Abstract property ‘required_staff’. When inheriting property validation,
only one superclass can define validation for property ‘required_staff’.
However, this validator IS the same since it belong to the same superclass, so it should NOT be a problem for MATLAB to validate it (as also stated in the page I linked at the beginning).
So, what’s going on? is this a bug, or it’s me that I’m missing something? Ideas for some workarounds (except including a set.required_staff method which on all the possible vehicles around)? oop, subclassing, superclass, properties validation MATLAB Answers — New Questions









