MATLAB Object-Oriented Programming

(Joyce) #1

Packages Create Namespaces


In this section...
“Package Folders” on page 6-25
“Internal Packages” on page 6-26
“Referencing Package Members Within Packages” on page 6-26
“Referencing Package Members from Outside the Package” on page 6-27
“Packages and the MATLAB Path” on page 6-28

Package Folders


Packages are special folders that can contain class folders, function, and class definition
files, and other packages. The names of classes and functions are scoped to the package
folder. A package is a namespace within which names must be unique. Function and class
names must be unique only within the package. Using a package provides a means to
organize classes and functions. Packages also enable you to reuse the names of classes
and functions in different packages.

NotePackages are not supported for classes created prior to MATLAB Version 7.6 (that
is, classes that do not use classdef).

Package folders always begin with the + character. For example,

+mypack
+mypack/pkfcn.m % a package function
+mypack/@myClass % class folder in a package

The parent of the top-level package folder must be on the MATLAB path.

Listing the Contents of a Package

List the contents of a package using the help command:

help event
Contents of event:
EventData - event.EVENTDATA Base class for event data
PropertyEvent - event.PROPERTYEVENT Event data for object property events

Packages Create Namespaces 6-

Free download pdf