Overview of Objects in Maple
Introduction to Objects
Objects in Maple
Objects are a programming construct that allow data and procedures to be encapsulated together. A class describes the contents (the data and procedures) of a group of objects. Objects that belong to a class are called instances of the class. The contents of an object are referred to as its members. There are two types of members: data members and member procedures. The member procedures of an object are called methods. An object's members have access controls which limit where the member can be accessed from, similar to modules. Members declared exported can be accessed from anywhere. Members declared local can only be accessed from within the object's methods.
In Maple, objects are a special type of module. Thus routines for working with modules also work with objects.
There are many benefits of object oriented programming.
The implementation of a class can be changed radically without changing the interface of exported methods. Thus code that uses the objects will not need to change when the internal implementation changes.
As objects are self-contained they can be easily reused.
Objects can define methods that allow them to integrate with standard Maple syntax. Thus users can create objects that can be used like builtin types.
A set of classes can implement a common set of exports. Thus a procedure that uses only the common exports will work with any objects from any of the classes without needing to know which particular class the objects belong to.
Objects in Maple are created using the syntax for creating modules or by copying existing objects. When using the module declaration syntax, adding option object will create an object instead of a module. The declaration defines the class instantiated by the object. Names declared local are internal to the object and cannot be accessed from outside of the object. Names declared exported can be accessed outside of the object. To create a new object by copying an existing one, use the Object function.
For a detailed discussion of creating objects in Maple, see Creating a New Object.
Exported methods are called using standard function call syntax, and not module member syntax (:-). To call the method m of an object o, call
m( o ):
For more information about methods, see Overview of Object Methods.
Overloading builtin Routines
Objects in Maple can define methods that will be invoked when an object is passed into certain Maple routines of type builtin. For example, if an object has a map method, that method is invoked when that object is passed into the map function.
For a detailed discussion of overloading builtin routines for objects, see Objects Overloading builtin Routines.
Objects in Maple can implement methods that will be automatically invoked when those objects are used with certain operators. For example an object with a + method can be used in sum expressions, and the object's + method will be invoked. This allows objects to be used naturally in Maple expressions.
For a detailed discussion of implementing operators for objects, see Objects Overloading Operators.
Objects and Types
All objects are of type object. In addition type and :: can be used to determine if an object is an instance of a particular class by passing an object of the expected class as the type. You can refine this type checking by defining the ModuleType method.
There is a set of special methods that a class can define that will be used in particular situations. See the method specific help pages for complete details.
ModuleCopy: The ModuleCopy method is invoked when an object is copied via the Object routine.
ModuleType: The ModuleType method is invoked when attempting to determine if an object is of a particular class. It allows a class to have a more precise type check.
ModulePrint: The ModulePrint method is invoked when a module is pretty-printed.
ModuleDeconstruct: The ModuleDeconstruct method is invoked when an object is converted to a 1-dimensional form, usually Maple syntax.
ModuleApply: The ModuleApply method is invoked when an object is used as a function in a function call expression.
ModuleLoad: The ModuleLoad method is invoked when the object class is read in from a library.
ModuleUnload: The ModuleUnload method is invoked when an object is collected.
ModuleIterator: The ModuleIterator method creates an interface that can be used to iterate over the contents of the object.
Download Help Document