TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Classic View

Use Monospaced Font
Show HTML Part by Default
Condense Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender: "Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
X-To: "Robert I. Eachus" <[log in to unmask]>
Date: Tue, 24 Nov 1998 16:05:11 -0800
Reply-To: AdaWorks <[log in to unmask]>
From: AdaWorks <[log in to unmask]>
In-Reply-To: <[log in to unmask]>
MIME-Version: 1.0
Parts/Attachments: TEXT/PLAIN (52 lines)

I always appreciate your insight into these issues. Mr. Mize wants to
implement a

               object.method(parameter list)

syntax.  This can be done by combining a generic with private package where
the tagged type is in the private part of the package specification.  The
actual object would be declared in the body.  Here is an abbreviated sample.

 type Item is private;
 Maximum : in Positive;
package Anonymous_Stack is
  procedure Push (Stack_Item : in  Item);
  procedure Pop  (Stack_Item : out Item);
  -- other operations
  type Stack_Set is array (Positive range <>) of Item;
  type Stack is tagged record
     Top  : Natural := 0;
     Data : Stack_Set(1..Maximum);
  end record;
  procedure Push (S : in out Stack; Stack_Item : in  Item);
  procedure Pop  (S : in out Stack; Stack_Item : out Item);
end Anonymous_Stack;

Now any instantiation of this will permit the client to call using the
object.method(paramter-list) syntax.  Also, it is still extensible. This
design is analogous to the C++ public/protected/private model where the
package body is the the private part, the Ada private part is like the
protected part and the public part is self-evident.  Variations on this theme
can be concoted using pointers to improve the encapsulation.

Even though we can do this in Ada, it is probably a contrivance to accomodate
some defensive notion of syntax rather than a model of good design or
coding style.


Richard Riehle
[log in to unmask]
AdaWorks Software Engineering
Suite 30
2555 Park Boulevard
Palo Alto, CA 94306
(650) 328-1815
FAX  328-1112