MATLAB Object-Oriented Programming

(Joyce) #1
Objects

A class is like a template for the creation of a specific instance of the class. This instance
or object contains actual data for a particular entity that is represented by the class. For
example, an instance of a bank account class is an object that represents a specific bank
account, with an actual account number and an actual balance. This object has built into
it the ability to perform operations defined by the class, such as making deposits to and
withdrawals from the account balance.

Objects are not just passive data containers. Objects actively manage the data contained
by allowing only certain operations to be performed, by hiding data that does not need to
be public, and by preventing external clients from misusing data by performing
operations for which the object was not designed. Objects even control what happens
when they are destroyed.

Encapsulating Information

An important aspect of objects is that you can write software that accesses the
information stored in the object via its properties and methods without knowing anything
about how that information is stored, or even whether it is stored or calculated when
queried. The object isolates code that accesses the object from the internal
implementation of methods and properties. You can define classes that hide both data and
operations from any methods that are not part of the class. You can then implement
whatever interface is most appropriate for the intended use.

References


[1] Shalloway, A., J. R. Trott, Design Patterns Explained A New Perspective on Object-
Oriented Design.. Boston, MA: Addison-Wesley 2002.

[2] Gamma, E., R. Helm, R. Johnson, J. Vlissides, Design Patterns Elements of Reusable
Object-Oriented Software. Boston, MA: Addison-Wesley 1995.

[3] Freeman, E., Elisabeth Freeman, Kathy Sierra, Bert Bates, Head First Design
Patterns. Sebastopol, CA 2004.

3 MATLAB Classes Overview

Free download pdf