MATLAB Object-Oriented Programming

(Joyce) #1

Functions in Private Folders Within Class Folders


Private folders contain functions that are accessible only from functions defined in folders
immediately above the private folder. Any functions defined in a private folder inside
a class folder become methods of the class that have private access.


If a class folder contains a private folder, only the class defined in that folder can access
functions defined in the private folder. Subclasses do not have access to superclass
private functions. For more information on private folders, see “Private Functions”.


If you want a subclass to have access to the private functions of the superclass, define the
functions as protected methods of the superclass. Specify the methods with the Access
attribute set to protected.


Dispatching to Methods in Private Folders


If a class defines functions in a private folder that is in a class folder, then MATLAB
follows these precedence rules when dispatching to the private functions vs. a local
function defined in the classdef file:



  • Using dot notation (obj.methodName), a function in a private folder takes
    precedence over a local function defined in the classdef file.

  • Using function notation (methodName(obj)), a local function defined in the
    classdef file takes precedence over the function in the private folder.


No Class Definitions in Private Folders


You cannot put class definitions (classdef file) in private folders because doing so would
not meet the requirements for class or path folders.


Class Precedence and MATLAB Path


When there are multiple class definition files with the same name, the file location on the
MATLAB path determines the file precedence. All class definition files before a class on
the path take precedence, whether or not the definitions are contained in a class folder.
The class takes precedence over all class definition files occurring later on the path.


For example, consider a path with the following folders, containing the files indicated.


Folders Containing Class Definitions
Free download pdf