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,342dcd67e9ca73ee X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: tagged record child: override constructor? Date: 13 Sep 2005 14:55:47 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1126591134.797303.318920@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1126637748 31760 192.74.137.71 (13 Sep 2005 18:55:48 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 13 Sep 2005 18:55:48 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:4623 Date: 2005-09-13T14:55:47-04:00 List-Id: Jeffrey Carter writes: > sean.gilbertson@gmail.com wrote: > > I have a tagged record that is declared private, along with a > > constructor function which returns an instance. I do this to enforce > > the assignment of several required fields in the record, so if you know > > how to do this another way, please let me know! > > It depends on what you mean by "enforce the assignment of several > required fields". It is impossible to force the client to call your > function, though you can arrange things so that the type is useless to > the client if the client doesn't first call your function. [... lots of good possibilities snipped...] There's another way to "enforce...": package P is type T(<>) is private; function Make_T(...) return T; private type T is record... end P; use P; Now clients can't create uninitialized objects of type T: X: T; -- illegal type T_Ptr is access T; Y: T_Ptr := new T; -- illegal type R is record Component: T; -- illegal end record; type A is array(...) of T; -- illegal The client is forced to call Make_T: X: T := Make_T(...); -- OK Y: T_Ptr := new T'(Make_T(...)); -- OK etc. - Bob