comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: pointers & OOP
Date: 1999/05/14
Date: 1999-05-14T00:00:00+00:00	[thread overview]
Message-ID: <m3lnesqn6i.fsf@mheaney.ni.net> (raw)
In-Reply-To: CFXIZOA$6wN3EwM8@jr-and-assoc.demon.co.uk

John Robinson <john@jr-and-assoc.demon.co.uk> writes:

> >> The use (in general) of one "major" type per package goes back to my
> >
> >Well, now its become one "major" type per package. This is a lot weaker
> >than your original claim. I might even agree with this one, 
> 
> Yes - if I have a fault it is getting suckered into replying quickly and
> not reviewing the words before sending (I actually thought I used the
> word "major" or "primary" or similar in the original posting - but I
> probably didn't).  In any case, any implementation or secondary types I
> use are not (in general) tagged types.

One time you need to combine types in the same package is when you're
using a factory method.

A factory method takes an instance of one (tagged) type, and returns an
instance of another (tagged) type.  Something like:

  function Factory_Method (O : T1) return T2'Class;

The operation is primitive for T1, and depends on types T1 and T2,
therefore both types must be declared in the same package.

Study the article Iterator and Factory Methods Combined, in the Nov 98
ACM patterns archive.  In that example a stack has a factory method that
returns an iterator.

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


Below is the elided spec.  There are two types in the same package, type
Root_Stack and type Root_Iterator.

Type Root_Stack has a factory method, Start_At_Top, that returns an
instance of an iterator appropriate for iteration over that kind of
stack.

   generic
      type Item_Type is private;
   package Stacks is

      type Root_Stack is
        abstract tagged limited null record;  -- type T1


      procedure Push
        (Item : in     Item_Type;
         On   : in out Root_Stack) is abstract;

      procedure Pop
        (Stack : in out Root_Stack) is abstract;

      ...


      type Root_Iterator is
        abstract tagged null record;          -- type T2

      function Start_At_Top
        (Stack : Root_Stack)
         return Root_Iterator'Class is abstract;  -- the factory method


      function Is_Done
        (Iter : Root_Iterator)
        return Boolean is abstract;

      function Get_Item
        (Iter : Root_Iterator)
         return Item_Type is abstract;

      procedure Advance
        (Iter : in out Root_Iterator) is abstract;

      ...

   end Stacks;



Declaring the data structure and its iterator together in the same
package is a very natural idiom.  

The reason Booch didn't have two types per package (data structure type
plus iterator type) in his component library is that he didn't have
active iterators.  










  reply	other threads:[~1999-05-14  0:00 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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     ` Francois Godme
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 [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
1999-05-01  0:00 Tom Moran
replies disabled

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