Eigenschaften
Eigenschaftserklärung, Attribute und Zugriffsmethoden
Eigenschaften enthalten Objektdaten. Klassen definieren dieselben Eigenschaften für alle Objekte, aber jedes Objekt kann einzigartige Datenwerte aufweisen. Eigenschaftsattribute kontrollieren, welche Funktionen oder Methoden auf die Eigenschaft zugreifen dürfen. Sie können Funktionen definieren, die ausgeführt werden, wenn Sie Eigenschaftswerte einstellen oder abfragen. Eigenschaften können Ereignisse auslösen, wenn der Code auf deren Werte zugreift.
Funktionen
Klassen
dynamicprops | Superclass for classes that support dynamic properties |
matlab.metadata.DynamicProperty | Describe dynamic property of MATLAB object |
event.DynamicPropertyEvent | Event data for dynamic property events |
matlab.metadata.Property | Describe property of MATLAB class |
matlab.metadata.Validation | Describes property validation |
matlab.metadata.FixedDimension | Fixed dimension in property size specification |
matlab.metadata.UnrestrictedDimension | Unrestricted dimension in property size specification |
matlab.metadata.ArrayDimension | Size information for property validation |
matlab.lang.OnOffSwitchState | Represent on and off states with logical values |
Themen
Definieren von Eigenschaften und Einrichten von Attributen
- Ways to Use Properties
Class properties can be defined to satisfy different use cases. - Property Syntax
Define class properties using attributes and validators that control behavior. - Property Attributes
Attributes control the behavior of properties. - 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. - Define Class Properties with Constant Values
Use a class withConstant
properties to define constant values. - 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.
Eigenschaftsvalidierung
- Validate Property Values
You can restrict property values to a size and class, and apply functions to validate assigned values. - Property Class and Size Validation
Define class and size requirements for a property. - Property Validation Functions
Property validation functions enable you to check the values being assigned to properties. - Metadata Interface to Property Validation
Programmatically determine the size, class, and validation functions that validate the values assigned to properties.
Methoden für Zugriff auf Eigenschaften
- Property Get and Set Methods
Property access methods execute code when property values are referenced or assigned. - Get and Set Methods for Dependent Properties
Define get and set access methods for dependent properties.
Dynamische Eigenschaften
- Dynamic Properties — Adding Properties to an Instance
You can add instance data to an object derived from thedynamicprops
class. - 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.