Class Attributes

Table of 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.

Attribute Name

Class

Description

Hidden

logical

(default = false)

If set to true, the class does not appear in the output of MATLAB® commands or tools that display class names.

InferiorClasses

cell

(default = {})

Use this attribute to establish a precedence relationship among classes. Specify a cell array of meta.class objects using the ? operator.

The built-in classes double, single, char, logical, int64, uint64, int32, uint32, int16, uint16, int8, uint8, cell, struct, and function_handle are always inferior to user-defined classes and do not show up in this list.

See Specifying Class Precedence

ConstructOnLoad

logical

(default = false)

If true, the class constructor is called automatically when loading an object from a MAT-file. Therefore, the construction must be implemented so that calling it with no arguments does not produce an error.

See Saving and Loading Objects

Sealed

logical

(default = false)

If true, the class can be not be subclassed.

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. This means that, for example, you might use multiple properties definition blocks so you can apply different attribute setting to different properties.

Inheritance of Superclass Attributes

Class attributes are not inherited. Therefore, superclass attributes do not affect subclasses, with the exception of InferiorClasses attribute. See Specifying Class Precedence for more information on this attribute.

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 key word, as shown below:

classdef (attribute-name = expression, ...) ClassName

   properties (attribute-name = expression, ...)
      ...
   end
   methods (attribute-name = expression, ...)
      ...
   end
   events (attribute-name = expression, ...)
      ...
   end
end

Evaluating Expressions in Attribute Assignments

The term expression in the statements above is used to mean any legal MATLAB expression that evaluates to a single array. The expression is evaluated when the class definition is first needed and the resulting value is treated as a constant.

The MATLAB language evaluates the expression in its own context and cannot reference variables or the class being defined. Attribute expressions can reference static methods and static properties of other classes and use the MATLAB path context of the class at the time of definition. This means the expression cannot access variables in the MATLAB workspace, but can access any function and static method or property that is on your path at the time the class definition is evaluated.

For example, in the following classdef line, the Sealed attribute is set to logical true only if a certain directory is on the MATLAB path.

classdef (Sealed = isdir('myDir'))
  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS