TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

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

Print Reply
Subject:
From:
AdaWorks <[log in to unmask]>
Reply To:
Date:
Tue, 24 Nov 1998 16:05:11 -0800
Content-Type:
TEXT/PLAIN
Parts/Attachments:
TEXT/PLAIN (52 lines)
Robert,

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.

generic
 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
private
  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


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

ATOM RSS1 RSS2