Subclass Definition

Syntax and design of subclasses

Learn how to implement subclasses, call superclass methods from subclasses, and control what classes can derive from a superclass.

Functions

superclasses Superclass names

Classes

matlab.mixin.Heterogeneous Superclass for heterogeneous array formation

Topics

Class Hierarchies

Hierarchies of Classes — Concepts

Organizing classes into hierarchies facilitates the reuse of code.

Heterogeneous Arrays

Heterogeneous arrays can contain objects of different class, but all objects in the array must derive from a common superclass.

Creating Subclasses

Define Subclasses — Syntax and Techniques

Specify superclasses on the classdef 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.

Sequence of Constructor Calls in Class Hierarchy

Control the order in which MATLAB® constructs objects in class hierarchy.

Modify Superclass Methods

Subclasses can modify inherited methods.

Modify Superclass Properties

Subclasses can modify inherited properties that are abstract or private.

Subclass 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.

Support Both Handle and Value Subclasses

Enable both handle and value classes to derive for a specific class.

Control Access to Class Members

Class Members Access

Determine what level of access is allowed for properties, methods, and events.

Sample Class Hierarchies

A Simple Class Hierarchy

A hierarchy of classes can be used to catalog financial assets.

Containing Assets in a Portfolio

Use a class to contain and manage the hierarchy of financial asset classes.

Was this topic helpful?