Property Attributes

Purpose of Property Attributes

Specifying attributes in the class definition enables you 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.

Specifying Property Attributes

Assign property attributes on the same line as the properties keyword:

properties (Attribute1 = value1, Attribute2 = value2,...)
   ...
end

For example, give the Data property private access:

properties (Access = private)
   Data
end

For more information on attribute syntax, see Attribute Specification.

Table of Property Attributes

All properties support the attributes listed in the following table. Attribute values apply to all properties defined within the properties...end code block that specifies the nondefault values.

Property Attributes

Attribute Name

Class

Description

AbortSet

logical

default = false

If true, MATLAB® does not set the property value if the new value is the same as the current value. MATLAB does not call the property set method, if one exists.

For handle classes, setting AbortSet to true also prevent the triggering of property PreSet and PostSet events.

See Assignment When Property Value Is Unchanged

Abstract

logical

default = false

If true, the property has no implementation, but a concrete subclass must redefine this property without Abstract being set to true.

  • Abstract properties cannot define set or get access methods. See Property Access Methods.

  • Abstract properties cannot define initial values. See Assigning a Default Value.

  • All subclasses must specify the same values as the superclass for the property SetAccess and GetAccess attributes.

  • Abstract=true use with the class attribute Sealed=false (the default).

Access (write only, cannot query this meta.property property. Use GetAccess and SetAccess in queries.)

  • enumeration, default = public

  • meta.class object

  • cell array of meta.class objects

Use Access to set both SetAccess and GetAccess to the same value. Query the values of SetAccess and GetAccess directly (not Access).

public – unrestricted access

protected – access from class or subclasses

private – access by class members only (not subclasses)

List of classes that have get and set access to this property. Specify classes as meta.class objects in the form:

  • A single meta.class object

  • A cell array of meta.class objects. An empty cell array, {}, is the same as private access.

See Class Members Access

Constant

logical

default = false

Set to true if you want only one value for this property in all instances of the class:

  • Subclasses inherit constant properties, but cannot change them.

  • Constant properties cannot be Dependent.

  • SetAccess is ignored.

See Define Class Properties with Constant Values for more information.

Dependent

logical

default = false

If false, property value is stored in object. If true, property value is not stored in object. The set and get functions cannot access the property by indexing into the object using the property name.

MATLAB does not display in the command window the names and values of Dependent properties that do not define a get method (scalar object display only).

Values returned by dependent property get methods are not considered when testing for object equality using isequal.

GetAccess

enumeration

default = public

public — unrestricted access

protected — access from class or subclasses

private — access by class members only (not from subclasses)

List classes that have get access to this property. Specify classes as meta.class objects in the form:

  • A single meta.class object

  • A cell array of meta.class objects. An empty cell array, {}, is the same as private access.

See Class Members Access

MATLAB does not display in the command window the names and values of properties having protected or private GetAccess or properties whose Hidden attribute is true.

The struct function defines fields for all properties when converting objects to structs.

GetObservable

logical

default = false

If true, and it is a handle class property, then you can create listeners for access to this property. The listeners are called whenever property values are queried. See Property-Set and Query Events

Hidden

logical

default = false

Determines if the property can be shown in a property list (e.g., Property Inspector, call to set or get, etc.).

MATLAB does not display in the command window the names and values of properties whose Hidden attribute is true or properties having protected or private GetAccess.

NonCopyable

logical

default = false

Determine if property value can be copied when object is copied.

You can set NonCopyable to true only in handle classes.

For more information, see Exclude Properties from Copy

PartialMatchPriority

Positive integer

default = 1

Use only with subclasses of matlab.mixin.SetGet. Define the relative priority of partial property name matches used in set and get methods.

For more information, see Set Priority for Matching Partial Property Names.

SetAccess

enumeration

default = public

public — unrestricted access

protected — access from class or subclasses

private — access by class members only (not from subclasses)

immutable — property can be set only in the constructor.

See Properties Containing Objects and Mutable and Immutable Properties

List classes that have set access to this property. Specify classes as meta.class objects in the form:

  • A single meta.class object

  • A cell array of meta.class objects. An empty cell array, {}, is the same as private access.

See Class Members Access

SetObservable

logical

default = false

If true, and it is a handle class property, then you can create listeners for access to this property. The listeners are called whenever property values are modified. See Property-Set and Query Events

Transient

logical

default = false

If true, property value is not saved when object is saved to a file. See Save and Load Process for Objects for more about saving objects.

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.

Related Topics