MATLAB Object-Oriented Programming

(Joyce) #1

Package Function and Class Method Name Conflict


Avoid importing an entire package using the * wildcard syntax. Doing so imports an
unspecified set of names into the local scope. For example, suppose that you have the
following folder organization:


+pkg/timedata.m % package function
+pkg/@MyClass/MyClass.m % class definition file
+pkg/@MyClass/timedata.m % class method


Import the package and call timedata on an instance of MyClass:


import pkg.*
myobj = pkg.MyClass;
timedata(myobj)


A call to timedata finds the package function, not the class method because MATLAB
applies the import and finds pkg.timedata first. Do not use a package in cases where
you have name conflicts and plan to import the package.


Clearing Import List


You cannot clear the import list from a function workspace. To clear the base workspace
only, use:


clear import


See Also


More About



  • “Packages Create Namespaces” on page 6-25


See Also
Free download pdf