MATLAB Object-Oriented Programming

(Joyce) #1

Why a Handle Class for Linked Lists?


Each node is unique in that no two nodes can be previous to or next to the same node.

For example, a node object, node, contains in its Next property the handle of the next
node object, node.Next. Similarly, the Prev property contains the handle of the previous
node, node.Prev. Using the three-node linked list defined in the previous section, you
can demonstrate that the following statements are true:

n1.Next == n2
n2.Prev == n1

Now suppose that you assign n2 to x:

x = n2;

The following two equalities are then true:

x == n1.Next
x.Prev == n1

But each instance of a node is unique so there is only one node in the list that can satisfy
the conditions of being equal to n1.Next and having a Prev property that contains a
handle to n1. Therefore, x must point to the same node as n2.

There has to be a way for multiple variables to refer to the same object. The MATLAB
handle class provides a means for both x and n2 to refer to the same node.

The handle class defines the eq method (use methods('handle') to list the handle
class methods), which enables the use of the == operator with all handle objects.

Related Information

For more information on handle classes, see “Comparison of Handle and Value Classes”
on page 7-2.

dlnode Class Synopsis


This section describes the implementation of the dlnode class.

3 MATLAB Classes Overview

Free download pdf