Object
create new instances of a class
Calling Sequence
Parameters
Description
Examples
Compatibility
Object( obj )
Object( obj, arg1, ... )
obj
-
an instance of an object
arg1, ...
arguments to a ModuleCopy routine
The Object routine creates a new object by copying a given object.
For information on declaring new objects, see Object,create. For an overview of objects in Maple, see object.
If the given object does not implement a ModuleCopy routine, then Object copies the values for each not-static member of the given object obj into the new object.
If the object does implement a ModuleCopy routine, then calling Object will invoke the ModuleCopy routine. Any additional parameters given (arg1, ...) will also be passed on to the ModuleCopy routine.
Implementing a ModuleApply routine that calls Object to invoke ModuleCopy makes applying the prototype object into an object factory.
module Obj() option object; local data := 0; export getData::static := proc( self::Obj ) self:-data; end; export setData::static := proc( self::Obj, d ) self:-data := d; end; end:
getData⁡Obj
0
newObj1≔Object⁡Obj
newObj1≔Object<<Obj,139704094130752>>
getData⁡newObj1
setData⁡newObj1,10
10
newObj2≔Object⁡newObj1
newObj2≔Object<<Obj,139704093220672>>
getData⁡newObj2
module Obj2() option object; local data := 0; export getData::static := proc( self::Obj2 ) self:-data; end; export ModuleCopy::static := proc( self::Obj2, proto::Obj2, d, $ ) if ( _npassed = 2 ) then self:-data := proto:-data; else self:-data := d; end; end; end:
getData⁡Obj2
newObj1≔Object⁡Obj2
newObj1≔Object<<Obj2,139704093186912>>
newObj2≔Object⁡Obj2,10
newObj2≔Object<<Obj2,139704093166368>>
module Obj3() option object; local data := 0; export getData::static := proc( self::Obj3 ) self:-data; end; export ModuleApply::static := proc( ) Object( Obj3, _passed ); end; export ModuleCopy::static := proc( self::Obj3, proto::Obj3, d, $ ) if ( _npassed = 2 ) then self:-data := proto:-data; else self:-data := d; end; end; end:
newObj1≔Obj3⁡
newObj1≔Object<<Obj3,139704092409120>>
newObj2≔Obj3⁡10
newObj2≔Object<<Obj3,139704092388608>>
The Object command was introduced in Maple 16.
For more information on Maple 16 changes, see Updates in Maple 16.
See Also
ModuleApply
ModuleCopy
object
Object,builtin
Object,create
Object,function_mechanism
Object,method
Object,operators
procedure
Download Help Document