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,8b95e4156b22b891 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Constructors? Date: 1998/08/25 Message-ID: #1/1 X-Deja-AN: 384557049 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1998-08-25T00:00:00+00:00 List-Id: Frank Ecke (franke@minet.uni-jena.de) wrote: : ... : But beware, although the term constructor exists in Ada, it should not be : confused with the notion used in OO. For example, in Java, constructors are : not inherited by the subclass. In Ada, a constructor is simply a primitive : operation of a tagged type and, therefore, it is propagated into the subclass. : Consider, for illustration, a simple hierarchy of geometrical figures (Point, : Circle, Rectangle, etc.): : ... This is not the only way to do things. The term "constructor" is not defined in the Ada reference manual. The closest thing to a built-in "constructor" in Ada is an aggregate. A user-defined constructor is just a function or procedure which creates and/or initializes an object. It might or might not be a primitive operation of the type, and the type might or might not be tagged. There are various coding conventions that have been developed for defining constructor-like operations. Some of these use primitive operations, others use operations that are specifically *not* primitive operations because of a desire that they *not* be inherited. The easiest way to declare an operation which is not primitive, and hence not inherited, is to declare it in a sub-package or child package. I personally like the idea of putting constructors in a child package because of my experience that only a subset of the clients of an abstraction create new instances of the abstraction. A much larger subset of the clients simply manipulate existing instances. Furthermore (in my experience), adding new, possibly specialized constructors is a more frequent operation than adding other kinds of primitive operations. By putting the constructors in a child package (or multiple child packages) most of the clients are isolated from changes to constructors. Finally, rather than explicit "constructors," the design pattern called a "factory" is often a preferable approach. Factories hide from the caller which particular type of object is created, and simply promise that its type is derived from some particular (usually abstract) type. That is often all you need to know in an OO language, especially when manipulating most objects by reference (i.e., using access values). : Frank -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA