MATLAB Object-Oriented Programming

(Joyce) #1

Methods in Class Design


In this section...
“Class Methods” on page 9-2
“Examples and Syntax” on page 9-2
“Kinds of Methods” on page 9-3
“Method Naming” on page 9-4

Class Methods


Methods are functions that implement the operations performed on objects of a class.
Methods, along with other class members support the concept of encapsulation—class
instances contain data in properties and class methods operate on that data. This design
allows the internal workings of classes to be hidden from code outside of the class, and
thereby enabling the class implementation to change without affecting code that is
external to the class.

Methods have access to private members of their class including other methods and
properties. This encapsulation enables you to hide data and create special interfaces that
must be used to access the data stored in objects.

Examples and Syntax


For an example to get started writing classes, see “Create a Simple Class” on page 2-2

For sample code and syntax, see “Methods and Functions” on page 5-15

For a discussion of how to create classes that modify standard MATLAB behavior, see
“Methods That Modify Default Behavior” on page 17-2.

For information on the use of @ and path directors and packages to organize your class
files, see “Class Files and Folders” on page 5-2

For the syntax to use when defining classes in more than one file, see “Methods in
Separate Files” on page 9-11

9 Methods — Defining Class Operations

Free download pdf