MATLAB Object-Oriented Programming

(Joyce) #1

Comparison of MATLAB and Other OO Languages


In this section...
“Some Differences from C++ and Java Code” on page 5-62
“Object Modification” on page 5-63
“Static Properties” on page 5-67
“Common Object-Oriented Techniques” on page 5-68

Some Differences from C++ and Java Code


The MATLAB programming language differs from other object-oriented languages, such
as C++ or Java in some important ways.

Public Properties

Unlike fields in C++ or the Java language, you can use MATLAB properties to define a
public interface separate from the implementation of data storage. You can provide public
access to properties because you can define set and get access methods that execute
automatically when assigning or querying property values. For example, the following
statement:

myobj.Material = 'plastic';

assigns the char vector plastic to the Material property of myobj. Before making the
actual assignment, myobj executes a method called set.Material (assuming the class
of myobj defines this method), which can perform any necessary operations. See
“Property Access Methods” on page 8-50 for more information on property access
methods.

You can also control access to properties by setting attributes, which enable public,
protected , or private access. See “Property Attributes” on page 8-9 for a full list of
property attributes.

No Implicit Parameters

In some languages, one object parameter to a method is always implicit. In MATLAB,
objects are explicit parameters to the methods that act on them.

5 Class Definition—Syntax Reference

Free download pdf