属性
属性声明、特性和访问方法
属性包含对象数据。类会为所有对象定义相同的属性,但每个对象都可以具有唯一的数据值。属性特性用于控制哪些函数或方法可以访问该属性。您可以定义每次设置或查询属性值时都会执行的函数。当代码访问属性的值时,属性可能会触发事件。
函数
类
dynamicprops | 支持动态属性的类的超类 |
meta.DynamicProperty | 描述 MATLAB 对象的动态属性 |
event.DynamicPropertyEvent | 动态属性事件的事件数据 |
meta.property | 描述 MATLAB 类的属性 |
meta.Validation | 描述属性验证 |
meta.FixedDimension | 属性大小设定中的固定维度 |
meta.UnrestrictedDimension | 属性大小设定中不受限制的维度 |
meta.ArrayDimension | 属性验证的大小信息 |
matlab.lang.OnOffSwitchState | 使用逻辑值表示开关状态 |
主题
定义属性和设置特性
- 使用属性的方式
可以定义类属性来满足不同用例。 - 属性语法
使用控制行为的特性和验证器来定义类属性。 - 属性特性
特性控制属性的行为。 - Mutable and Immutable Properties
You can control what code can set property values. - Initialize Property Values
Classes can assign default values to properties, and you can change these values during object construction. - 定义具有常量值的类属性
使用具有Constant
属性的类来定义常量值。 - Properties Containing Objects
Properties assigned objects as default values construct that object only once when the class is first loaded. Also, assignment to contained object properties behaves differently depending on whether the object is a handle or value.
属性验证
- 验证属性值
您可以限制属性值的大小和类,并应用函数来验证赋给属性的值。 - Property Class and Size Validation
Define class and size requirements for a property. - 属性验证函数
属性验证函数使您能够检查赋给属性的值。 - Metadata Interface to Property Validation
Programmatically determine the size, class, and validation functions that validate the values assigned to properties.
属性访问方法
- 属性 get 和 set 方法
当引用属性值或为其赋值时,属性访问方法会执行一些代码。 - 从属属性的 get 和 set 方法
为从属属性定义 get 和 set 访问方法。
动态属性
- 动态属性 - 向实例添加属性
您可以将实例数据添加到从dynamicprops
类派生的对象中。 - Set and Get Methods for Dynamic Properties
You can implement what are effectively access methods for dynamic properties. - Dynamic Property Events
You can define listeners forPropertyAdded
andPropertyRemoved
events on dynamic properties. - Dynamic Properties and ConstructOnLoad
Use theConstructOnLoad
attribute to save and load dynamic properties.