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,449b3383afc55069 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Child package: private type and IO Date: 1998/02/27 Message-ID: #1/1 X-Deja-AN: 329353162 Content-Transfer-Encoding: 8bit References: <6c2r0l$iic$1@madmax.keyway.net> <6cbuat$cg3$1@nnrp1.dejanews.com> Content-Type: text/plain; charset=ISO-8859-1 Organization: Estormza Software Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-02-27T00:00:00+00:00 List-Id: In article <6cbuat$cg3$1@nnrp1.dejanews.com>, sparre@cats.nbi.dk wrote: >A parent-client package example: > > -- file: parent.ads > > package Parent is > > type Object is ...; > > function Initialise return Object; > > end Parent; Note that this is NOT the way to organize this package if type Object is tagged. For a tagged type, constructors - defined as functions returning a value of the type - should return the class-wide type, or should be declared in a nested package, ie package P is type T is tagged ...; package Constructors is function New_T return T; end; ... end P; -or- package P is type T is tagged ...; function New_T return T'Class; ... end P; The problem is that very often you use the "transitivity of visibility" technique to get direct visitibility to the type and its operations, with a null extension, ie type NT is new P.T with null record; but if T has primitive operations that are functions returning type T, then type NT "goes abstract," and the poor client has to override them. This is NOT what you want to have happen. By declaring the constructor in a nested package, then the function isn't primitive anymore, and so it is not inherited. Therefore, any derivation doesn't go abstract, because there are not inheritable functions that return the specific type. The same effect may be achieved by making the return type class-wide. Then the function is no longer primitive, and so is not inherited during a derivation. Therefore, the derived type does not go abstract, which is the behavior we want. I'll also make an Ada style point. Please do not name a type "type Object is..." This is VERY confusing, because an object is an object, not a type. Objects are the memory locations that store a value of a type. So when refer to an object's type as "Object," then how do you refer to the object? A type should be named using a noun phrase, such as type Text_File is ...; type Singly_Linked_List is ...; type Storage_Element_Array is array ...; type Ownship_Heading is ...; type Integer is ...; A good guideline is, Be consistant with the style in the reference manual. There are NO types in the RM named "Object," so there should be none in your code either.