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,bc7fae210b5e1392 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: how do i include 111111 in an enumaration type ? Date: 1999/10/13 Message-ID: <380485d2_1@news1.prserv.net>#1/1 X-Deja-AN: 536228953 Distribution: world Content-transfer-encoding: 7bit References: <7tsq3o$92p$1@minus.oleane.net> <38021792_4@news1.prserv.net> <7ttuvt$ssb$1@minus.oleane.net> <38033f0b_3@news1.prserv.net> <7tvpd6$1mg$1@nnrp1.deja.com> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 13 Oct 1999 13:14:58 GMT, 129.37.62.46 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-10-13T00:00:00+00:00 List-Id: In article , lutz@iks-jena.de (Lutz Donnerhacke) wrote: > From reading the Rationale and Reference Manual, the novice (like me) can > not deduce, that this 'Unchecked_'-Package is required for normal usage. Unchecked_Deallocation is not required for normal usage. There are idioms for implementing abstractions that use the heap or some form of indirection. Basically, you want to hide all of that from the client. The type Unbounded_String is a good example of an abstraction that internally uses heap, but hides this fact from the client. This is how a well-designed abstraction should be: it should hide information. The problem is that many programmers come from a C or otherwise non-object oriented background, and use raw pointers (really, heap allocation) in the public part of the abstraction. This is wrong. The idiom for class-wide programming (in which indirection is necessary, because a class-wide type is indefinite) is to declare the root type as limited and indefinite, and let each specific type in the class export its own constructor: package P is type Root_T (<>) is abstract tagged limited private; type Root_T_Access is access all Root_T; Free (O : in out Root_T_Access); ... end P; package P.C is type T is new Root_T with private; function New_T return Root_T_Access; ... end P.C; A client *never* calls "new" directly; he always goes through a constructor. In the example above, the client does however have to call a deconstructor (Free) directly. The deconstructor is implemented by dispatching on a private primitive operation that returns the object to the storage pool for the specific type. Realize of course that indirection is not always required. In the observer pattern, for example, both object and subject are allocated statically, without any heap or pointer use. > Instead the longish discussions about accessibility rules lead me to the > belief, that access types are like smart pointers. It is possible to implement a smart pointer yourself, so that you don't have to call Free manually. See the smart pointer article in the design patterns archive. For other smart pointer examples, just search for "handle" or "do_free". Matt -- The new standards [for science curricula in Kansas] do not forbid the teaching of evolution, but the subject will no longer be included in statewide tests for evaluating students--a virtual guarantee, given the realities of education, that this central concept of biology will be diluted or eliminated, thus reducing courses to something like chemistry without the periodic table, or American history without Lincoln. Stephen Jay Gould, Time, 23 Aug 1999