Object - Maple Help

# Online Help

###### All Products    Maple    MapleSim

Object

create new instances of a class

 Calling Sequence Object( obj ) Object( obj, arg1, ... )

Parameters

 obj - an instance of an object arg1, ... - arguments to a ModuleCopy routine

Description

 • 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.

Examples

 > 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:
 > $\mathrm{getData}\left(\mathrm{Obj}\right)$
 ${0}$ (1)
 > $\mathrm{newObj1}≔\mathrm{Object}\left(\mathrm{Obj}\right)$
 ${\mathrm{newObj1}}{≔}{\mathrm{Object<>}}$ (2)
 > $\mathrm{getData}\left(\mathrm{newObj1}\right)$
 ${0}$ (3)
 > $\mathrm{setData}\left(\mathrm{newObj1},10\right)$
 ${10}$ (4)
 > $\mathrm{newObj2}≔\mathrm{Object}\left(\mathrm{newObj1}\right)$
 ${\mathrm{newObj2}}{≔}{\mathrm{Object<>}}$ (5)
 > $\mathrm{getData}\left(\mathrm{newObj2}\right)$
 ${10}$ (6)
 > 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:  > $\mathrm{getData}\left(\mathrm{Obj2}\right)$  ${0}$ (7)  > $\mathrm{newObj1}≔\mathrm{Object}\left(\mathrm{Obj2}\right)$  ${\mathrm{newObj1}}{≔}{\mathrm{Object<>}}$ (8)  > $\mathrm{getData}\left(\mathrm{newObj1}\right)$  ${0}$ (9)  > $\mathrm{newObj2}≔\mathrm{Object}\left(\mathrm{Obj2},10\right)$  ${\mathrm{newObj2}}{≔}{\mathrm{Object<>}}$ (10)  > $\mathrm{getData}\left(\mathrm{newObj2}\right)$  ${10}$ (11)  > 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:
 > $\mathrm{newObj1}≔\mathrm{Obj3}\left(\right)$
 ${\mathrm{newObj1}}{≔}{\mathrm{Object<>}}$ (12)
 > $\mathrm{getData}\left(\mathrm{newObj1}\right)$
 ${0}$ (13)
 > $\mathrm{newObj2}≔\mathrm{Obj3}\left(10\right)$
 ${\mathrm{newObj2}}{≔}{\mathrm{Object<>}}$ (14)
 > $\mathrm{getData}\left(\mathrm{newObj2}\right)$
 ${10}$ (15)

Compatibility

 • The Object command was introduced in Maple 16.
 • For more information on Maple 16 changes, see Updates in Maple 16.

 See Also