MATLAB Object-Oriented Programming

(Joyce) #1

Subclasses of Built-In Types with Properties


In this section...
“Specialized Numeric Types with Additional Data Storage” on page 12-68
“Subclasses with Properties” on page 12-68
“Property Added” on page 12-69
“Methods Implemented” on page 12-69
“Class Definition Code” on page 12-69
“Using ExtendDouble” on page 12-72
“Concatenation of ExtendDouble Objects” on page 12-75

Specialized Numeric Types with Additional Data Storage


Subclass built-in numeric types to create customized data types that inherit the
functionality of the built-in type. Add or modify functionality to that provided by the
superclass by implementing class methods.

Providing additional data storage in the subclass by defining properties can be a useful
extension to the built-in data class. However, the addition of properties to the subclass
requires the subclass to define methods to implement standard array behaviors.

For more information, see “Subclasses of MATLAB Built-In Types” on page 12-50.

Subclasses with Properties


When a subclass of a built-in class defines properties, default indexing and concatenation
do not work. The default subsref, subsasgn, horzcat, and vertcat functions cannot
work with unknown property types and values. Therefore, the subclass must define these
behaviors by implementing these methods.

This sample implementation of the ExtendDouble class derives from the double class
and defines a single property. The ExtendDouble class definition demonstrates how to
implement indexing and concatenation for subclasses of built-in classes

12 How to Build on Other Classes

Free download pdf