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,772ae8afc5db35f2 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Can't export object of private type Date: 1999/03/02 Message-ID: #1/1 X-Deja-AN: 450226926 Sender: matt@mheaney.ni.net References: <7b1k4h$13k6@news3.newsguy.com> <36daf246.1947172@news.pacbell.net> NNTP-Posting-Date: Mon, 01 Mar 1999 20:01:03 PDT Newsgroups: comp.lang.ada Date: 1999-03-02T00:00:00+00:00 List-Id: tmoran@bix.com (Tom Moran) writes: > > 1) Have only one instance > > 2) Are polymorphic > I've probably missed something, but does "Are polymorphic" mean the > user can define a descendant type? In which case he can create an > object of that new type, or in fact multiple objects of that type, > each of which "is" an instance of the original type, contradicting > requirement (1). No? No. If you make the type limited and indefinite, no one outside the package can create an instance. The root package of the subsystem exports an instance function that returns a pointer to the singleton object declared in the body. Because the pointer designates the class-wide type, the object can be any type in the class. This is an example of a package with'ing its own child. The primitive operations of the type are all access parameters. When you invoke an operation of the type, you pass the result of the instance function to the operation. That way, you don't even have to dereference the return value (which is a pointer). This is how you implement a "once function" in Ada. The difference is that you don't need to put anything on the heap, which is how Ada was designed. This is one of the reasons why there's no compelling reason to have a garbage collector in Ada. All four goals are thus satisfied.