If You are Unfamiliar with OOP Matlab
For those not familiar with matlab, matlab provides a variety of access attributes when creating member variables. All member variables are essentially C# properties in their own right, who's get and set values default to normal access and assignment. Any (and I mean any) member variable can have its get and set "operators" overwritten like so:
%typical OOP class
classdef MyClass
%both Properties in the C# sense *and* member variables
%default access is public, put it here for clarity
properties (Access = public)
myProperty
myMember
end
methods
function self = set.myProperty(self, value)
% doesn't invoke recursion, actually references a variable called
% self.myProperty, which if you overwrite the get.property,
% you can't actually access outside of set and get
self.myProperty = ...
end
function value = get.myProperty(self)
...
end
%constructor, self is the class instance
function self = MyClass(value)
self.myMember = value;
%actually calls set.myProperty
self.myProperty = value;
end
end
end
You can't call get.myProperty or set.myProperty either, it isn't in the language at all.
If you want a real C# property you have to do the following, as at times you can't refer to the real value used inside the myProperty
functions if you have set defined(as you can only refer to assignment of that value inside that function) or get (where it would always call the get function).
classdef MyClass
%both Properties in the C# sense *and* member variables
%default access is public, put it here for clarity
properties (Access = private)
myMember
end
properties (Access = public, Dependent = true)
myProperty
end
methods
function self = set.myProperty(self, value)
% since the property is "dependent" it no longer can refer to a
% variable called self.myProperty, it can only refer to other properties
self.myMember = ...
end
function value = get.myProperty(self)
value = self.myMember
end
end
end
Matlab Property Attribute Background
Now I'm interested in specifically the following property combinations: Access
, GetAccess
, SetAccess
, and Depedent
:
Access which defines if the property is public, private or protected [1]
(Access = public|private|protected)
Get/Set propertes (this works like access above, but with get and set functions)[1]
(GetAccess = public|private|protected)
(SetAccess = public|private|protected)
Dependent (doesn't actually have a value directly associated with it, can't assign to its name inside of its get and set, looks like a C# property afterward, but can be private and protected as well)
(Dependent = true|false)
Question
Would a property with both get and set defined that wasn't Dependent
ever be a valid use case? It seems like you are hiding the value itself from the class this way, you are making the value an implementation detail to your own class. What about properties with either get
or set
defined but not both?
Would the validity change if the Set/GetAccess
or general Access
changed to private
, protected
or public
?
On the same line, should those properties with redefined get
and set
ever be used in implementation code? You have no clue what they actually do and to a casual observer they just look like normal members, so it would seem like their use would be dangerous in class implementation code, it seems like this would also necessitate a separate naming convention.
[1] (Note it can also define specific classes that have access to the property that are unrelated, the validity of this is outside the scope of the question).