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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,901038687c38f61c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread2.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: Idiom for a class and an object in Ada References: From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 20 Oct 2004 07:04:44 GMT NNTP-Posting-Host: 64.185.133.124 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.atl.earthlink.net 1098255884 64.185.133.124 (Wed, 20 Oct 2004 00:04:44 PDT) NNTP-Posting-Date: Wed, 20 Oct 2004 00:04:44 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:5493 Date: 2004-10-20T07:04:44+00:00 List-Id: Jeffrey Carter writes: > The Ada idiom for a singleton is package-as-object; the obvious > extension from "single" to "a few" is a generic package. That might have been true in Ada83, but it is not true in Ada95. The intended Ada95 mechanism for controlling instance creation is to declare the type as limited and indefinite, and for the package to provide a factory function to create instances of the type. > However, a discriminated type such as you described may well be a > viable alternative. It's the idea that you need a family of tagged > types, type extension, and all that entails for something this simple. The original problem had to do with where and how to declare well-known objects. That problem is orthogonal to the need for type extension and dynamic binding. If you don't need type extension or dynamic binding, then clearly the type doesn't need to be tagged. See the genealogy directories in ai302/examples at the tigris site for some examples. Actually, I realized after I had written genealogy2 that I should have implemented the parser like this: package Parser is type Data_Type (<>) is limited private; function Student (Data : Data_Type) return String; function Advisor (Data : Data_Type) return String; ... procedure Iterate (Process : not null access procedure (Data : Data_Type)); ... end Parser; Here's a case where the instances are created by the package on-the-fly, as the passive iteration occurs. None of the types declared in Data_Maps or Relation_Maps are tagged, but they are all limited and indefinite.