Class Attributes - MATLAB & Simulink (original) (raw)
Main Content
Specifying Class Attributes
All classes support the attributes listed in the following table. Attributes enable you to modify the behavior of class. Attribute values apply to the class defined within the classdef
block.
classdef (Attribute1 = value1, Attribute2 = value2,...) ClassName ... end
Class Attributes
Attribute Name | Class | Description |
---|---|---|
Abstract | logical(default =false) | If specified as true, this class is an abstract class (cannot be instantiated).See Abstract Classes and Class Members for more information. |
AllowedSubclasses | matlab.metadata.Class object or cell array ofmatlab.metadata.Class objects | List classes that can subclass this class. Specify subclasses as matlab.metadata.Class objects in the form:A single matlab.metadata.Class objectA cell array of matlab.metadata.Class objects. An empty cell array, {}, is the same as aSealed class (no subclasses).Specify matlab.metadata.Class objects using the ?ClassName syntax only. See Specify Allowed Subclasses for more information. |
ConstructOnLoad | logical(default =false) | If true, MATLABĀ® calls the class constructor when loading an object from a MAT file. Classes defined with this attribute must have a no-argument constructor.See Default Save and Load Process for Objects for more information. |
HandleCompatible | logical(default =false) for value classes | If specified as true, this class can be used as a superclass for handle classes. All handle classes areHandleCompatible by definition. See Handle Compatible Classes for more information. |
Hidden | logical(default =false) | If true, this class does not appear in the output of the superclasses or help functions. |
InferiorClasses | matlab.metadata.Class object or cell array ofmatlab.metadata.Class objects | Use this attribute to establish a precedence relationship among classes. Specify a cell array of matlab.metadata.Class objects using the ? operator. The fundamental classes are always inferior to user-defined classes and do not show up in this list.See Class Precedence. |
Sealed | logical (default =false) | If true, this class cannot be subclassed. |
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. |
Specifying Attributes
Attributes are specified for class members in the classdef
, properties
, methods
, and events
definition blocks. The particular attribute setting applies to all members defined within that particular block. You can use multiple properties
, methods
, and events
definition blocks to apply different attribute setting to different class members.
Superclass Attribute Values Are Not Inherited
Class attributes settings are not inherited, so superclass attribute values do not affect subclasses.
Attribute Syntax
Specify class attribute values in parentheses, separating each attribute name/attribute value pair with a comma. The attribute list always follows the classdef
or class member keyword, as shown:
classdef (attribute-name = expression, ...) ClassName
properties (attribute-name = expression, ...) ... end methods (attribute-name = expression, ...) ... end events (attribute-name = expression, ...) ... end end
Class-Specific Attributes
Some MATLAB classes define additional attributes that you can use only with the class hierarchies that define these attributes. See the specific documentation for the classes you are using for information on any additional attributes supported by those classes.