Proprietà
Dichiarazione di proprietà, attributi e metodi di accesso
Le proprietà contengono i dati dell’oggetto. Le classi definiscono le stesse proprietà per tutti gli oggetti, ma ogni oggetto può avere valori di dati unici. Gli attributi delle proprietà controllano quali funzioni o metodi possono accedere alla proprietà. È possibile definire funzioni che vengono eseguite ogni volta che vengono impostati o interrogati i valori della proprietà. Le proprietà possono attivare eventi quando il codice accede ai loro valori.
Funzioni
Classi
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 |
Argomenti
Definizione delle proprietà e impostazione degli attributi
- 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.
Convalida delle proprietà
- 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.
Metodi di accesso alle proprietà
- 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.
Proprietà dinamiche
- 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.