MATLAB Object-Oriented Programming

(Joyce) #1

Folders Containing Class Definitions


In this section...
“Class Definitions On the Path” on page 6-17
“Class and Path Folders” on page 6-17
“Using Path Folders” on page 6-17
“Using Class Folders” on page 6-18
“Functions in Private Folders Within Class Folders” on page 6-19
“Class Precedence and MATLAB Path” on page 6-19
“Changing Path to Update Class Definition” on page 6-21

Class Definitions On the Path


To call a class method, the class definition must be on the MATLAB path, as described in
the next sections.

Class and Path Folders


There are two types of folders that can contain class definition files.


  • Path folders — The folder is on the MATLAB path and the folder name does not begin
    with an @ character. Use this type of folder when you want multiple classes in one
    folder. However, the entire class definition must be contained in one .m file.

  • Class folders — The folder name begins with an @ character followed by the class
    name. The folder is not on the MATLAB path, but its parent folder is on the path. Use
    this type of folder when you want to use multiple files for one class definition.


See the path function for information about the MATLAB path.

Using Path Folders


The class definition files in the folders are on the MATLAB path. Therefore, class
definitions placed in path folders behave like any ordinary function with respect to
precedence—the first occurrence of a name on the MATLAB path takes precedence over
all subsequent occurrences of the same name.

Folders Containing Class Definitions.................... 6-

Free download pdf