La traduction de cette page n'est pas à jour. Cliquez ici pour voir la dernière version en anglais.
Définition de sous-classes
Syntaxe et design des sous-classes
Découvrez comment implémenter des sous-classes, appeler les méthodes de la superclasse depuis les sous-classes et contrôler les classes qui peuvent être dérivées d’une superclasse.
Outils
Class Diagram Viewer | Create diagrams with class details and hierarchies (depuis R2021a) |
Fonctions
superclasses | Names of superclasses |
Classes
matlab.diagram.ClassViewer | Create class diagrams in Class Diagram Viewer app (depuis R2021a) |
matlab.mixin.Heterogeneous | Superclass for heterogeneous array formation |
Rubriques
Hiérarchies de classes
- 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.
Créer des sous-classes
- Subclass Syntax
Specify superclasses on the classdef line after the class name. - Design Subclass Constructors
Specify superclasses on theclassdef
line in the class file. - Call Superclass Methods on Subclass Objects
Subclass methods can override inherited superclass methods. Subclass methods can call the superclass method that they override. - 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.
Compatibilité avec la classe Handle
- 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.
Contrôler l’accès aux membres d’une classe
- Class Members Access
Determine what level of access is allowed for properties, methods, and events.