Programming Previous page   Next Page

Private Methods

Private methods can be called only by other methods of their class. You define private methods by placing the associated M-files in a private subdirectory of the @classname directory. In the example,

the method updateObj has scope only within the classname class. This means that updateObj can be called by any method that is defined in the @classname directory, but it cannot be called from the MATLAB command line or by methods outside of the class directory, including parent methods.

Private methods and private functions differ in that private methods (in fact all methods) have an object as one of their input arguments and private functions do not. You can use private functions as helper functions, such as described in the next section.

Helper Functions

In designing a class, you may discover the need for functions that perform support tasks for the class, but do not directly operate on an object. These functions are called helper functions. A helper function can be a subfunction in a class method file or a private function. When determining which version of a particular function to call, MATLAB looks for these functions in the order listed above. For more information about the order in which MATLAB calls functions and methods, see How MATLAB Determines Which Method to Call.


Previous page  Creating Objects Debugging Class Methods Next page

© 1994-2005 The MathWorks, Inc.