MATLAB Object-Oriented Programming

(Joyce) #1

obj = mypack.myClass(arg1,arg2,...);


Calling class methods does not require the package name because you have an object of
the class. You can use dot or function notation:


obj.myMethod(arg)
myMethod(obj,arg)


A static method requires the full class name, which includes the package name:


mypack.myClass.stMethod(arg)


Referencing Package Members from Outside the Package


Functions, classes, and other packages contained in a package are scoped to that
package. To reference any of the package members, prefix the package name to the
member name, separated by a dot. For example, the following statement creates an
instance of MyClass, which is contained in mypack package.


obj = mypack.MyClass;


Accessing Class Members — Various Scenarios


This section shows you how to access various package members from outside a package.
Suppose that you have a package mypack with the following contents:


+mypack
+mypack/myfcn.m
+mypack/@MyFirstClass
+mypack/@MyFirstClass/myFcn.m
+mypack/@MyFirstClass/otherFcn.m
+mypack/@MyFirstClass/MyFirstClass.m
+mypack/@MySecondClass
+mypack/@MySecondClass/MySecondClass.m
+mypack/+mysubpack
+mypack/+mysubpack/myFcn.m


Invoke the myFcn function in mypack:


mypack.myFcn(arg)


Create an instance of each class in mypack:


Packages Create Namespaces
Free download pdf