Programming |
|
Tips for C++ and Java Programmers
If you are accustomed to programming in other object-oriented languages, such as C++ or Java, you will find that the MATLAB programming language differs from these languages in some important ways:
- In MATLAB, method dispatching is not syntax based, as it is in C++ and Java. When the argument list contains objects of equal precedence, MATLAB uses the left-most object to select the method to call.
- In MATLAB, there is no equivalent to a destructor method. To remove an object from the workspace, use the
clear
function.
- Construction of MATLAB data types occurs at runtime rather than compile time. You register an object as belonging to a class by calling the
class
function.
- When using inheritance in MATLAB, the inheritance relationship is established in the child class by creating the parent object, and then calling the
class
function. For more information on writing constructors for inheritance relationships, see Building on Other Classes.
- When using inheritance in MATLAB, the child object contains a parent object in a property with the name of the parent class.
- In MATLAB, there is no passing of variables by reference. When writing methods that update an object, you must pass back the updated object and use an assignment statement. For instance, this call to the
set
method updates the name
field of the object A
and returns the updated object.
- In MATLAB, there is no equivalent to an abstract class.
- In MATLAB, there is no equivalent to the C++ scoping operator.
- In MATLAB, there is no virtual inheritance or virtual base classes.
- In MATLAB, there is no equivalent to C++ templates.
| Setting Up Class Directories | | Designing User Classes in MATLAB | |
© 1994-2005 The MathWorks, Inc.