Definición de subclases
Sintaxis y diseño de subclases
Aprenda a implementar subclases, llamar a métodos de superclases desde subclases y controlar qué clases pueden derivar de una superclase.
Herramientas
Class Diagram Viewer | Create diagrams with class details and hierarchies (desde R2021a) |
Funciones
superclasses | Names of superclasses |
Clases
matlab.diagram.ClassViewer | Create class diagrams in Class Diagram Viewer app (desde R2021a) |
matlab.mixin.Heterogeneous | Superclass for heterogeneous array formation |
Temas
Jerarquías de clases
- Hierarchies of Classes — Concepts
Organizing classes into hierarchies facilitates the reuse of code. - Designing Heterogeneous Class Hierarchies
Heterogeneous arrays can contain objects of different class, but all objects in the array must derive from a common superclass.
Creación de subclases
- Sintaxis de subclases
Especifique superclases en la línea classdef después del nombre de la clase. - Design Subclass Constructors
Specify superclasses on theclassdef
line in the class file. - Llamar a los métodos de superclases en objetos de subclases
Los métodos de subclases pueden reemplazar métodos de superclases heredados. Los métodos de subclases pueden llamar al método de superclase al que reemplazan. - Control Sequence of Constructor Calls
Control the order in which MATLAB® constructs objects in class hierarchy. - Modify Inherited Methods
Subclasses can modify inherited methods. - Modify Inherited Properties
Subclasses can modify inherited properties that are abstract or private. - Subclassing Multiple Classes
Multiple inheritance can lead to conflicting definitions. All superclasses must be free of conflicts in definition. - Specify Allowed Subclasses
Classes can restrict the classes that can derive from it.
Compatibilidad de clases de identificadores
- Handle Compatible Classes
Enable both handle and value classes to derive from a specific class. - How to Define Handle-Compatible Classes
Handle compatible classes have applications for mixin and abstract superclasses. - Methods for Handle-Compatible Classes
Handle-compatible class methods must work with both handle and value objects. - Handle-Compatible Classes and Heterogeneous Arrays
Heterogeneous class hierarchies impose certain restrictions when classes are handle compatible.
Controlar acceso a miembros de clases
- Class Members Access
Determine what level of access is allowed for properties, methods, and events.