MATLAB: How to disable modification to an object that is a property of another object in MATLAB 7.11 (R2010b)

MATLAB

I have a class A that contains a property which is is an object of handle class B. I want to implement a locking mechanism, which allows the user to instantiate class B, set it as a property of an object of class A, and then "lock" the property of object A.
Once the property is locked, changing the handle to object B should not be permitted. However with the locked handle, I should be able to access the object of class B, but not modify it.

Best Answer

Property access attributes cannot be modified at runtime in MATLAB.
However, there are ways to prevent the program from modifying the values of a property, once it has been "locked".
Approach 1:
Define the 'SetAccess' attribute for the property of class A that holds the object of class B as 'immutable'. Similarly define all properties of class B as 'immutable'. In this way, you can only set the values of the properties for the first time in the constructor.
Approach 2:
A more flexible approach is to define a flag property, and write your own code for 'set.propertyname' method in the class A. In this method, the property which contains the handle to object of class B, should be modified only if the flag is reset. Note that once the handle is available the user would still be able to read it, and modify the object of class B, but cannot modify the handle itself. As an example:
methods
set.propertyname(object,value)
% Write code for checking flag and assign value only if flag reset
end
end
Further, to avoid modifying the object of class B, the value of flag would have to be queried from object of class A and implement a logic similar to the one above to make each property modifiable/not modifiable.