Property Attributes
Purpose of Property Attributes
You can specify attributes in the class definition to customize the behavior of properties for specific purposes. Control characteristics like access, data storage, and visibility of properties by setting attributes. Subclasses do not inherit superclass member attributes.
Specify Property Attributes
Assign property attributes on the same line as the properties
keyword.
properties (Attribute1 = value1, Attribute2 = value2,...) ... end
For example, define a property Data
with
private
access.
properties (Access = private) Data end
You can use a simpler syntax for attributes whose values are true
.
The attribute name by itself implies true, and adding the not operator (~) to the name
implies false. For example, this block defines abstract properties.
properties (Abstract)
...
end
Table of Property Attributes
All properties support the attributes listed in this table. Attribute values apply to
all properties defined within the properties...end
code block that
specifies the nondefault values. Attributes that you do not explicitly defined take
their default values.
Property Attributes
Attribute | Values | Additional Information |
---|---|---|
|
| For handle classes only. Setting For more information, see Assignment When Property Value Is Unchanged. |
|
| Abstract properties cannot define set or get access methods. See Property Get and Set Methods. Abstract properties cannot define initial values. A sealed class cannot define abstract members. |
|
| Use Specifying See Class Members Access for more information. |
|
| Subclasses inherit constant properties but cannot change them. Constant properties cannot also be defined as dependent. The value of See Define Class Properties with Constant Values for more information. |
|
| You can define set methods for dependent properties, but the set method cannot actually set the value of the property. It can take other actions, such as setting the value of another property. See When to Use Set Methods with Dependent Properties for an example. Values returned by dependent property get methods
are not considered when testing for object equality using |
|
| Specifying In the Command Window, MATLAB does not display the names and values of properties with
All subclasses must specify
the same values as the superclass for the property
See Class Members Access for more information. |
|
| See Property-Set and Query Events for more information. |
|
| In the Command Window, MATLAB does not display the names and values of properties whose
Hidden attribute is true .
However, hidden properties are visible in the Class Diagram Viewer
app. |
|
| You can set For more information, see Exclude Properties from Copy. |
| Positive integer – Defines the relative priority of partial
property name matches used in | Use only with subclasses of For more information, see Set Priority for Matching Partial Property Names. |
|
| All subclasses must specify the same values as the superclass
for the property For more information, see Class Members Access, Properties Containing Objects, and Mutable and Immutable Properties. |
|
| See Property-Set and Query Events for more information. |
|
| See Default Save and Load Process for Objects for more information. |
|
| Properties defined as All properties
defined with the
See Weak Reference Handles for examples and more information. |
Framework attributes | Classes that use certain framework base classes have framework-specific attributes. See the documentation for the specific base class you are using for information on these attributes. |
Property Access Lists
You can use lists of matlab.metadata.Class
instances for the
Access
, GetAccess
, and
SetAccess
attributes. For example, this class declares access
lists for the Prop1
and Prop2
properties.
classdef PropertyAccess properties (GetAccess = {?ClassA, ?ClassB}) Prop1 end properties (Access = ?ClassC) Prop2 end end
For Prop1
:
Classes
ClassA
andClassB
have get access toProp1
.All subclasses of
ClassA
andClassB
have get access toProp1
.Access lists are not inherited, so subclasses of
PropertyAccess
do not have get access toProp1
unless they explicitly define that access.
For Prop2
:
ClassC
has get and set access toProp2
.All subclasses of
ClassC
have get and set access toProp2
.Access lists are not inherited, so subclasses of
PropertyAccess
do not have access toProp2
unless they explicitly define that access.