Hi David,
back from a meeting so I can give you an example for each strategy.
Example1
--------------
Content of program "example1.rex":
.test~~new~~new~~new
say .test~counter "instances created so far"
o=.test~new
say o~class~counter "instances created so far"
::class test
::method init class
expose counter
counter=0
::attribute counter class
::method new class
expose counter
counter+=1
forward class (super)
Output of running "rexx example1.rex":
3 instances created so far
4 instances created so far
Example 2 (using a metaclass)
--------------------------------------------
Content of program "example2.rex":
.test~~new~~new~~new
say .test~counter "instances created so far"
o=.test~new
say o~class~counter "instances created so far"
::requires "metaclass2.rex"
::class test metaclass metaclassCounter
Content of program "metaclass2.rex":
::class metaclassCounter subclass class public
::method init
expose counter
counter=0
::attribute counter
::method new
expose counter
counter+=1
forward class (super)
Output of running "rexx example2.rex":
3 instances created so far
4 instances created so far
HTH,
---rony
On 04.12.2013 15:26, Rony G. Flatscher wrote:
> Hi David,
> On 04.12.2013 15:22, David Ashley wrote:
>> All -
>>
>> I had a need last night to create a class that could count the number of
>> instances that had been created using class methods. I could not find an
>> example of this in any of our documentation. Maybe I just did not look
>> in the right place but it was not obvious to me if it was there.
>>
>> Could someone point me to an example of this in our documentation I
>> would appreciate it very much. If such an example does not exist then I
>> would be happy to add one to our docs once I can locate a good example.
>>
>> At this point I am just looking for verification that an example
>> does/does not exist in our docs.
> you would have to add a class method named "new" to your class which counts
> its invocation numbers
> (using a class attribute that you initialize in a class INIT method). Please
> do not forget to
> forward the invocation to the class INIT and class NEW method to their
> superclasses.
>
> HTH,
>
> ---rony
>
> P.S.: Also, you could use metaclasses for that purpose and on demand just use
> the class' directive's
> METACLASS subkeyword to point to that class. In that case be aware that a
> specialization of the
> class named CLASS is needed and that the "init" and "new" methods there are
> instance methods.
------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel