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,1f0bebbd5edf4a6f X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Please help a newbie with Booch/Ada. Date: 1998/08/30 Message-ID: #1/1 X-Deja-AN: 386218157 Sender: matt@mheaney.ni.net References: <35DCCE3A.9EAE78D8@pacbell.net> NNTP-Posting-Date: Sun, 30 Aug 1998 12:45:25 PDT Newsgroups: comp.lang.ada Date: 1998-08-30T00:00:00+00:00 List-Id: Stephen Leake 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.