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/02/28 Message-ID: #1/1 X-Deja-AN: 449656932 Sender: matt@mheaney.ni.net References: <7b1k4h$13k6@news3.newsguy.com> <7b4517$2bbr@news3.newsguy.com> NNTP-Posting-Date: Sun, 28 Feb 1999 14:30:40 PDT Newsgroups: comp.lang.ada Date: 1999-02-28T00:00:00+00:00 List-Id: Samuel Mize writes: > By "singleton" and (1) you mean that there can exist only one object > of the type. But a visible type makes that impossible to ensure, so > the approach you were taking is fatally flawed. Oh, the humanity. This is incorrect. Implement the type as tagged, limited, and indefinite, which prevents anyone from declaring instances of the type. The 4 goals listed are all achievable, indeed very simply. > I would represent each singleton with a package, which gives 1 and 3, > and use programming by extension to get points 2 and 4. Specifically, > we start with: I like the idea of a state machine package, but he wants dynamic dispatching. The way to implement this abstraction is like this: package P is type T (<>) is abstract tagged limited private; type T_Access is access all T'Class; function Ref return T_Access; private end P; package P.Q is type NT is new T with private; ... end; with P.Q; package body P is O : aliased Q.NT; function Ref return T_Access is begin return O'Access; end; ... end P; The function Ref, which returns a pointer to an object declared in the body, is analogous to Eiffel's once functions.