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,4a5bab72e3ac47fc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.sol.net!posts.news.twtelecom.net!nnrp2.twtelecom.net!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada References: <18qpcb693v2zz$.1es3pcrwk4eiu$.dlg@40tude.net> Subject: Re: Dynamich Dispatching... Date: Fri, 15 Oct 2004 14:27:12 -0400 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Message-ID: <417013a9$0$91009$39cecf19@news.twtelecom.net> Organization: Time-Warner Telecom NNTP-Posting-Date: 15 Oct 2004 18:15:05 GMT NNTP-Posting-Host: 4fe578ea.news.twtelecom.net X-Trace: DXC=jNIK14>9FZGZE[lA2<`InOC_A=>8kQj6MhHXa^^g6TZDdH4leX5AV6DdYZAA8S:_^oY\KX_N X-Complaints-To: abuse@twtelecom.net Xref: g2news1.google.com comp.lang.ada:5290 Date: 2004-10-15T18:15:05+00:00 List-Id: "Dmitry A. Kazakov" wrote in message news:uv6ftd235dgf$.1px68p9wf1tjb.dlg@40tude.net... > On Mon, 04 Oct 2004 21:02:44 +1000, Brian May wrote: > > Then if one really needs a contravariant result, then Create should be > class-wide. It is as simple as: > > function Create return X'Class; The issue is not whether one needs a contravariant result. Rather, the issue is whether the constructor is primitive for the type or not. In general, constructors should *not* be primitive. One way to do that is to declare the constructor in a nested package: package P is type X is tagged ...; package Constructors is function Create return X; end; end P; A constructor should always return a specific type, not a class-wide type. Your example above is wrong, since it would require the declaration of an object whose type is class-wide, and hence force the use of dispatching. Clearly that's wrong, when you know the specific type of object you want to create. The only time is makes sense for a constructor to return a class-wide type is when this is a factory method pattern. In that case, the operation is primitive for parameter type: package Q is type X is abstract tagged ...; type Y is abstract tagged ...; function Create (O : X) return Y'Class is abstract; end Q;