Is is possible to control the order of inherited class properties?
Mostrar comentarios más antiguos
Consider two simple classes, where one inherits from the other:
First class:
classdef Example_Class_1 < handle
properties
Property1
Property2
end
end
Second class:
classdef Example_Class_2 < Example_Class_1
properties
Property3
end
end
Now, if I create an Example_Class_2 object, its properties are listed as follows:
Example_Class_2
ans =
Example_Class_2 with properties:
Property3: []
Property1: []
Property2: []
Is there some alternative syntax I can use when defining Example_Class_2, such that Property1 and Property 2 (the inherited properties) appear before Property3 when an Example_Class_2 object is created?
Respuesta aceptada
Más respuestas (2)
Steven Lord
el 19 de Jun. de 2020
1 voto
Have your class inherit from matlab.mixin.CustomDisplay and override the getPropertyGroups method. See the "Customize Property Display" section on this documentation page for an example.
1 comentario
Harry Dymond
el 19 de Jun. de 2020
Ashwin
el 19 de Jun. de 2020
0 votos
Although there isn’t any explicit way by which the order of printing of the properties can be changed, you can attempt to overload the properties() function in order to print the properties of a required class in the order you require it. The below question does the same for dynamic properties, it could be of reference.
https://www.mathworks.com/matlabcentral/answers/9777-oop-dynamic-properties-ordering-is-very-strange
However, the process does seem rather tedious to reproduce.
1 comentario
Harry Dymond
el 19 de Jun. de 2020
Editada: Harry Dymond
el 19 de Jun. de 2020
Categorías
Más información sobre Labels and Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!