MATLAB Object-Oriented Programming

(Joyce) #1

Representing Hardware with Classes


In this section...
“Objective” on page 12-83
“Why Derive from int32” on page 12-83
“Implementation” on page 12-83
“Construct MuxCard Object” on page 12-84
“Call Methods of int32” on page 12-85

Objective


This example implements a class to represent an optical multiplex card. These cards
typically have several input ports and an output port. The MuxCard class represents the
ports by the port names and port data rates. The output rate of a multiplex card is the
sum of the input port data rates.

Why Derive from int32


The MuxCard class derives from the int32 class because 32–bit integers represent the
input port data rates. The MuxCard class inherits the methods of the int32 class, which
simplifies the implementation of this subclass. For example, numeric array indexing and
arithmetic operations work on MuxCard objects because the class inherits these
operations from the int32 class.

Implementation


Here is the definition of the MuxCard class. Notice that the input port rates initialize the
int32 portion of class.

classdef MuxCard < int32
properties
InPutNames
OutPutName
end

properties (Dependent = true)
OutPutRate

Representing Hardware with Classes
Free download pdf