Re: [BLACKBOX] Polymorphism

From: [at]} <Alexander>
Date: Sun, 23 Nov 2008 18:07:51 +0600

----boundary-LibPST-iamunique-1106078080_-_-
Content-type: text/plain

Hello!

AMAUN> I replaced the VAR record statements with pointers. Primarily I did
AMAUN> this because I can't call a method from an uninitialized pointer, so
AMAUN> there are fewer tests needed for good data.

  On the other hand, static RECORDs (not POINTERs) are allocated on
  stack, so there is zero dynamic memory overhead (no NEW/GC
  involved). The stack memory is released upon the exit from the
  procedure where the RECORD local variable is declared. Using static
  RECORDs is almost the same as passing their contents as parameters
  to the Do procedure, which they are, essentially, in this case.

  Yes, using POINTERs you will be "caught by the hand" if you pass an
unitialized NIL
  parameter, but even if you allocate the Helper with NEW, there is
  still no guarantee that it is initialized (you may forget to call
  Init, or whatever).

  There are two ways around it:
  1) always use a creation routine which performs initialization:
    PROCEDURE NewHelper (params): Helper;
    VAR res: Helper;
    BEGIN
         NEW (res);
         res.params := params (* initialization *)
         RETURN res
    END NewHelper;

    If you don't create instances of the Helper class outside the
    NewHelper procedure, this way guarantees that every existing
    (#NIL) instance is properly initialized;

  2) use ABSTRACT procedure Init, thus forcing every descendant class
  to implement it. But then you have to use a special creation procedure
  that makes sure the Init is actually called after NEW.

  The second approach sounds like too much for such a small and
  insignificant object with very short life span. The first approach,
  on the other hand, also works for the VAR-objects:
    PROCEDURE NewHelper (VAR res: Helper; params);
    BEGIN
         res.params := params (* initialization *)
    END NewHelper;

  In short: there is next to no added value in using POINTER TO
  objects in this case, but there is the added dynamic memory overhead
  (find a memory block, then release the memory block; memory fragmentation).

>> You may also consider "Action" instead of "Doer".
AMAUN> I decided on "Helper" but I'm not fully satisfied.

  "Iterator" is another option.

---=====---
 Alexander


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1106078080_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaW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iAgb2JqZWN0
cyBpbiB0aGlzIGNhc2UsIGJ1dCB0aGVyZSBpcyB0aGUgYWRkZWQgZHluYW1pYyBtZW1vcnkgb3Zl
cmhlYWRccGFyDQogIChmaW5kIGEgbWVtb3J5IGJsb2NrLCB0aGVuIHJlbGVhc2UgdGhlIG1lbW9y
eSBibG9jazsgbWVtb3J5IGZyYWdtZW50YXRpb24pLlxwYXINClxwYXINCj4+ICBZb3UgbWF5IGFs
c28gY29uc2lkZXIgIkFjdGlvbiIgaW5zdGVhZCBvZiAiRG9lciIuXHBhcg0KQU1BVU4+IEkgZGVj
aWRlZCBvbiAiSGVscGVyIiBidXQgSSdtIG5vdCBmdWxseSBzYXRpc2ZpZWQuXHBhcg0KXHBhcg0K
ICAiSXRlcmF0b3IiIGlzIGFub3RoZXIgb3B0aW9uLlxwYXINClxwYXINCi0tLT09PT09LS0tXHBh
cg0KIEFsZXhhbmRlclxwYXINClxwYXINClxwYXINCi0tLS1ccGFyDQpUbyB1bnN1YnNjcmliZSwg
c2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZGIEJMQUNLQk9YIiB0byBMSVNUU0VSVkBM
SVNUUy5PQkVST04uQ0h9fQBTLk9C
----boundary-LibPST-iamunique-1106078080_-_---
Received on Sun Nov 23 2008 - 13:07:51 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:50 UTC