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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2e2db8edf2656165 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread2.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: Matthew Heaney@MHEANEYIBMT43 Newsgroups: comp.lang.ada Subject: Re: Constructing an object References: From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 23 Sep 2005 12:24:08 GMT NNTP-Posting-Host: 24.149.57.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.atl.earthlink.net 1127478248 24.149.57.125 (Fri, 23 Sep 2005 05:24:08 PDT) NNTP-Posting-Date: Fri, 23 Sep 2005 05:24:08 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:5058 Date: 2005-09-23T12:24:08+00:00 List-Id: Maciej Sobczak writes: > Is it really enough? Consider this: > > with Shapes; > procedure Hello is > S : Shapes.Shape; -- oops, uninitialized Shape > begin > null; > end Hello; I should have been more specific. In addition to declaring the type as private, you have to either provide a default for the C component of the Shape record, or privately derive from Controlled and assign C a value in the Initialize operation. > It compiles fine (GNAT) and it allows me to declare an uninitialized > object of private type Shape. The only thing that private type gives me > is that I cannot tinker with its internals directly. This is good in > itself, but not enough to save me from having uninitialized objects. Right. > I think that the most general approach is with abstract types, You don't need abstract types for this problem. You would only need to declare the type abstract if you were declaring an interface (indeed, in Ada 2005 there's even a special keyword for that), for which you're unable to provide an implemention for some of the operations. > although > at the same time it looks like an overkill in simpler cases and not > without its own problems. In particular, it introduces an artifical > hierarchy of types (not counting the cases where the hierarchy already > exists at the design time, like with true Shapes, Animals, etc.). Right. In this case, you don't need an abstract type to be the root of your type hierarchy. > I miss constructors. The "real" ones. ;-) (no flame intended) Well, this issue has been discussed for a long time. In Ada you use a function for this purpose. The only snag is if this is a tagged type, then you have to treat value-returning functions with care. You probably want to make the function non-primitive. (Note that this is an error in my last post.) That means either wrap the value-returning functions in a nested package (or possibly as children), or return a class-wide type. The big improvement in Ada 2005 is that there's new syntax for initializing a return value (I showed it in one of my examles), that you can use even for limited types. (Only for limited types? Hopefully an ARG member will jump in here and, er, elaborate.)