comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Please help a newbie with Booch/Ada.
Date: 1998/08/30
Date: 1998-08-30T00:00:00+00:00	[thread overview]
Message-ID: <m3g1eer5uf.fsf@mheaney.ni.net> (raw)
In-Reply-To: upvducc1i.fsf@gsfc.nasa.gov

Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:

> Better would be to fix the Ada 95 Booch components to allow indefinite
> types. Find the declaration of Bc.Containers, and add "(<>)" as a
> discriminant to the object type. Be aware this might break lots of
> stuff; I haven't tried it.

The Booch components aren't broken.  Just build collections of
indefinate subtypes on top of collections of definate subtypes.  This
layer is sort of an adapter pattern, to convert between a handle
(definate, implemented as a pointer) and the item itself (indefinate).

It was suggested that one instantiate the (definate item) stack with
Ada.Strings.Unbounded.  However, this would put onus on the user of the
collection to change a string into an unbounded string, then put that
into the collection, and do the reverse when retrieving an item.

A hipper approach is for the client to write a stack adapter, and let
the conversion between String and Unbounded_String be hidden as an
implementation detail.  Something like:

package String_Stacks is

   type String_Stack is private;

   procedure Push (Source : in String; On : in out String_Stack);

   function Get_Top (Stack : String_Stack) return String;
...
private

   package Unbounded_String_Stacks is 
      new BC.Stacks.Unbounded (Ada.Strings.Unbounded.Unbounded_String);

   use Unbounded_String_Stacks;

   type String_Stack is
      record
         Rep : Unbounded_Stack;
      end record;

end String_Stacks;


package body String_Stacks is 

   procedure Push (Source : in String; On : in out String_Stack) is

      Stack : Unbounded_Stack renames On.Rep;
   begin
      Push (To_Unbounded_String (Source), On => Stack);
   end;

   function Get_Top (Stack : String_Stack) return String is
   begin
      return To_String (Get_Top (Stack.Rep));
   end;

...
end String_Stacks;


Now the client can use the stack in a natural way:

  Push ("Ada, je t'aime.", On => Stack);

declare
   Top : String renames Get_Top (Stack);
begin
...


A component library can't be all things to all people.  Better is to
provide a small-ish set of primitives from which clients can compose
their own custom-built abstractions.

Making all the containers take indefinate subtypes would be the worst of
all possible decisions, because that would mean _every_ instantiation
would use heap, even those clients that have definate subtypes.

The Booch Components (nor any lib) shouldn't get in the business of
deciding for the client how the memory manage indefinate subtypes.
Provide a container for definate subtypes, and let the client build an
adapter on top of that.





  parent reply	other threads:[~1998-08-30  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-20  0:00 Please help a newbie with Booch/Ada Lengyel Sandor
1998-08-21  0:00 ` Stephen Leake
1998-08-21  0:00   ` Lengyel Sandor
1998-08-27  0:00   ` Simon Wright
1998-08-30  0:00   ` Matthew Heaney [this message]
1998-09-01  0:00     ` Brian Rogoff
replies disabled

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