From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5394d9ca5f955366 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: pointers & OOP Date: 1999/05/01 Message-ID: #1/1 X-Deja-AN: 472949106 NNTP-Posting-Date: Sat, 01 May 1999 11:27:24 PDT Newsgroups: comp.lang.ada Date: 1999-05-01T00:00:00+00:00 List-Id: John Robinson writes: > It is difficult to do anything really useful with Ada 95 OOP features > without the use of pointers. No. For example, a factory method in Ada95 returns an object by-value: procedure Print (Stack : in Root_Stack'Class) is Iterator : Root_Iterator'Class := Get_Iterator (Stack); begin while not Is_Done (Iterator) loop Put (Get_Item (Iterator)); Advance (Iterator); end loop; end Print; Function Get_Iterator is a (dispatching) factory method that returns an object whose type is class-wide. The iterator object goes in the stack. No heap is used. Is_Done, Get_Item, Advance, are all dispatching operations. This is an example of what Jean-Pierre was talking about. No heap, no pointer. > Any collection class for example will need to use pointers, even if > the collection is based around a fixed length array. Yes, a collection whose items have a class-wide type will require pointer use. But you can use a smart pointer, so you don't have to worry about any pointer manipulation headaches. Gives you the same as a reference in other OO languages. > Having said that, Ada still provides a more predictable OO environment > with better compile time checking than other OO languages (that should > get the Java crowd going :-)). I don't think they'd disagree that Ada95 has better compile time checking. The argument is, How important is compile-time checking to the programmer? Most programmers are oblivious to the benefits of rigorous compile-time checking, and many programmers actually like having bugs (because they get to find them and fix them), so "Ada95 has better checking" is a tough sell. For some ideas on smart pointers, how to control instance creation, etc, peruse the articles (mostly Oct/Nov 98 to the present) in the Ada95 design patterns archive at the ACM. Matt