inheriting property and changing access
Afficher commentaires plus anciens
I have an abstract class 'TA_Component' with a property 'Length'. in general the propery should be set by the user.
nI also have have a subclass 'TA_rget<TA_Component' that has have a length of 0.
how would I make this happen? i tried to set length to be constant and got the messege "The definition of property 'Length' in class 'TA_rget' differs from its definition in the superclass 'TA_Component'. This is caused by either conflicting access permissions or differing values of the Constant
attribute.
Réponse acceptée
Plus de réponses (1)
Steven Lord
le 4 Nov 2020
0 votes
According to the documentation there are two conditions under which you can redefine superclass properties. I don't believe you can make a property Constant in the subclass if it wasn't already Constant in the superclass or make it non-Constant if it was Constant in the superclass. If you want it to be Constant make it Constant in both superclass and subclass.
2 commentaires
Nathan Blanc
le 4 Nov 2020
Steven Lord
le 4 Nov 2020
You attached TA_rget but not TA_Component, the superclass from which it inherits.
The problem is not that the propery is Abstract in the superclass and not Abstract in the subclass. That's fine.
The problem is (likely) that the property is not Constant in the superclass but Constant in the subclass. My guess at what the relevant section of the superclass looks like:
classdef TA_Component
properties(Abstract)
Length
end
% snip the rest of the class
end
and
classdef TA_rget<TA_Component
% any type of target in a TA system
properties (Constant)
%% unprotected properties
Length=0 % length [m]
N_Sol_Points=1 % number of points in solution
end
% snip the rest of the class
end
Either Length has to be Constant in both classes or Constant in neither class.
Catégories
En savoir plus sur Handle Classes dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!