comp.lang.ada
 help / color / mirror / Atom feed
* pointers & OOP
@ 1999-05-01  0:00 Matthew Heaney
  1999-05-01  0:00 ` Matthew Heaney
  1999-05-03  0:00 ` John Robinson
  0 siblings, 2 replies; 39+ messages in thread
From: Matthew Heaney @ 1999-05-01  0:00 UTC (permalink / raw)


John Robinson <john@jr-and-assoc.demon.co.uk> 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.

<http://www.acm.org/archives/patterns.html>

Matt





^ permalink raw reply	[flat|nested] 39+ messages in thread
* pointers & OOP
@ 1999-05-01  0:00 Tom Moran
  0 siblings, 0 replies; 39+ messages in thread
From: Tom Moran @ 1999-05-01  0:00 UTC (permalink / raw)


In GNAT chat, John Robinson said:
> It is difficult to do anything really useful with Ada 95 OOP features
> without the use of pointers.
Robert Dewar pointed to finalization actions as just one example
of using OOP without pointers, and Matthew Heaney said:
> ... it would be helpful to have a list of typical examples.
so here's another:
  Sometimes, perhaps for task-safety or resource ownership
reasons, the task that wants something done can't do it, but
needs to ask a different service task to do the job.  Rather
than have a proliferation of 'entry's in the service task, one
per type of job, make a single service entry that takes a
"Job:in out Job_To_Do'Class" parameter and whose 'accept' merely
calls a "Do_It(Job)" procedure.  Any time some new type of job
needs to be done, simply declare a child of Job_To_Do, with
appropriate places in the record extension for parameters, and
overide procedure Do_It(Job : in out Job_To_Do).  Then a call
to the service entry will dispatch to the desired Do_It routine
so the service task will actually be the one executing the Do_It
code.  Essentially you are using Job_To_Do's dispatch table to
pass a procedure pointer, and using the record extension to
hold the parameters, but you are getting the compiler to build,
and check, everything instead of relying on screwup-able
explicit pointers.





^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~1999-05-14  0:00 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-01  0:00 pointers & OOP Matthew Heaney
1999-05-01  0:00 ` Matthew Heaney
1999-05-03  0:00 ` John Robinson
1999-05-03  0:00   ` Samuel Mize
1999-05-04  0:00     ` Martin C. Carlisle
1999-05-04  0:00     ` Robert Dewar
1999-05-04  0:00   ` Robert Dewar
1999-05-04  0:00     ` Mike Silva
1999-05-05  0:00     ` John Robinson
1999-05-05  0:00       ` Robert Dewar
1999-05-08  0:00         ` Ehud Lamm
1999-05-05  0:00       ` Matthew Heaney
1999-05-05  0:00       ` Robert Dewar
1999-05-05  0:00         ` John Robinson
1999-05-06  0:00           ` Brian Rogoff
1999-05-07  0:00             ` dennison
1999-05-07  0:00               ` Brian Rogoff
1999-05-10  0:00                 ` dennison
1999-05-11  0:00                   ` Jean-Pierre Rosen
1999-05-11  0:00                     ` dennison
1999-05-10  0:00             ` John Robinson
1999-05-14  0:00               ` Matthew Heaney
1999-05-14  0:00                 ` David Botton
1999-05-14  0:00           ` Matthew Heaney
1999-05-14  0:00             ` Ed Falis
1999-05-06  0:00       ` Tom Moran
1999-05-06  0:00         ` John Robinson
1999-05-06  0:00           ` Tom Moran
1999-05-07  0:00             ` dennison
1999-05-07  0:00             ` dennison
1999-05-07  0:00             ` dennison
1999-05-10  0:00             ` John Robinson
1999-05-14  0:00         ` Matthew Heaney
1999-05-06  0:00       ` Simon Wright
1999-05-06  0:00         ` John Robinson
1999-05-08  0:00           ` Simon Wright
1999-05-10  0:00             ` John Robinson
1999-05-05  0:00     ` Francois Godme
  -- strict thread matches above, loose matches on Subject: below --
1999-05-01  0:00 Tom Moran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox