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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: nospam@thanks.com.au (Don Harrison) Subject: Re: Can't export object of private type Date: 1999/03/03 Message-ID: #1/1 X-Deja-AN: 450628185 Sender: news@syd.csa.com.au X-Nntp-Posting-Host: dev7 References: Organization: CSC Australia, Sydney Reply-To: nospam@thanks.com.au Newsgroups: comp.lang.ada Date: 1999-03-03T00:00:00+00:00 List-Id: Matt Heaney wrote: :Of course, you could do it the way you suggest. This is sort of an :extreme example, where you have a family of types, and each type in the :family has a singleton instance. : :I don't know why Don wants to do this (I've certainly never had such a :need), but I wanted to show that it is possible, and that in fact the :implementation is relatively simple. The actual context is.. A family of handlers is needed, each of which processes a specific type of data item received over an external interface. There should be one such handler per data item type and handlers share common behaviour. The handlers also need to be processed as a group (eg. for resetting state) so need to be storable in a polymorphic collection which may be processed by iterating over its elements. Hence, the requirement for a family of tagged singletons. Note, BTW, that the primitive operations for processing data items must belong to the handler hierarchy (rather than a parallel data item hierarchy) in the interests of faithful modelling. (IMO, implementations in which objects process themselves are nonsensical. One such example in the Ada Rationale has alerts handling themselves!). :It will take some time for programmers to grok the concept of limited :and indefinite types, and what it's buying you. They're somewhat tortured souls. Types whose objects: a) Must be (initialised when declared so they are constrained), yet b) Can't be (initialised by clients because they are limited), so c) Aren't (declarable by clients - a) and b) are contradictory for clients). :I have a few examples :of this idiom in the ACM patterns archive. : : Looks like you have some good stuff here. Thanks for publicising it. :I'm working on another pattern now that was inspired by this thread. An :abstract factory, implemented using smart pointers, is used to :initialize a singleton instance of a limited and indefinite type. Whew! :I'll post an announcement on CLA once it has been submitted (probably :tomorrow or the day after.) Interesting. -- Don (Harrison). donh at syd.csa.com.au