Lets say I have a superclass called rectangle:
classdef Rectangle
properties
width
height
x0 = 0
y0 = 0
angle = 0
end
methods
function obj = Rectangle(x0, y0, width, height, angle)
obj.x0 = x0;
obj.y0 = y0;
obj.width = width;
obj.height = height;
obj.angle = angle;
end
end
end
And I have a subclass called Map, in which I want all properties to be read-only once set:
classdef Map < Rectangle
properties (SetAccess=private)
filename
end
methods
function obj = Map(filename)
% Get info from map using a function that uses geotiffread
[x0, y0, width, height] = GetInfoFromMap(filename);
obj = obj@Rectangle(x0, y0, width, height, 0);
obj.filename = filename;
end
end
end
How can I make the inherited properties of Rectangle read-only within Map? I want the properties of any stand-alone (non Map) Rectangle object to remain changeable.
And also, how can I ensure that some of those properties can take only certain values? i.e. for my purposes a rectangle can have any angle, but I'd expect a map to always have an angle of 0. But if I try to create a set.angle method for Map to ensure that angle can only be 0, I get an error telling me that "Cannot specify a set function for property 'angle' in class 'BackgroundMap', because that property is not defined by that class."