Documentation

Class Attributes

指定类素质butes

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 theclassdefblock.

classdef(Attribute1=value1,Attribute2=value2,...)ClassName...end
For more information on attribute syntax, seeAttribute Specification.

Class Attributes

Attribute Name

Class

Description

Abstract

logical

(default =false)

If specified astrue, this class is an abstract class (cannot be instantiated).

SeeAbstract Classesfor more information.

AllowedSubclasses

meta.classobject or cell array ofmeta.classobjects

List classes that can subclass this class. Specify subclasses asmeta.classobjects in the form:

  • A singlemeta.classobject

  • A cell array ofmeta.classobjects. An empty cell array,{}, is the same as aSealedclass (no subclasses).

Specifymeta.classobjects using the?ClassNamesyntax only.

SeeSpecify Allowed Subclassesfor more information.

ConstructOnLoad

logical

(default =false)

Iftrue, MATLAB®calls the class constructor when loading an object from a MAT-file. Therefore, implement the constructor so it can be called with no arguments without producing an error.

SeeInitialize Objects When Loadingfor more information.

HandleCompatible

logical

(default =false) for value classes

If specified astrue, this class can be used as a superclass for handle classes. All handle classes areHandleCompatibleby definition. SeeHandle Compatible Classesfor more information.

Hidden

logical

(default =false)

Iftrue, this class does not appear in the output of thesuperclassesorhelpfunctions.

InferiorClasses

meta.classobject or cell array ofmeta.classobjects

Use this attribute to establish a precedence relationship among classes. Specify a cell array ofmeta.classobjects using the?operator.

The fundamental classes are always inferior to user-defined classes and do not show up in this list.

SeeClass PrecedenceandDominant Argument in Overloaded Graphics Functions.

Sealed

logical

(default =false)

Iftrue, this class cannot be subclassed.

Specifying Attributes

Attributes are specified for class members in theclassdef,properties,methods, andeventsdefinition blocks. The particular attribute setting applies to all members defined within that particular block. You can use multiplepropertiesdefinition blocks to apply different attribute setting to different properties.

Superclass Attributes Are Not Inherited

Class attributes are not inherited, so superclass attributes 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 theclassdefor class member keyword, as shown:

classdef(属性名称=表达式, ...)ClassNameproperties(属性名称=表达式, ...) ...endmethods(属性名称=表达式, ...) ...endevents(属性名称=表达式, ...) ...endend

Related Topics

Was this topic helpful?