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,901038687c38f61c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!newsfeeds.sol.net!posts.news.twtelecom.net!nnrp2.twtelecom.net!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada References: <9175719.eWmeGlFrVu@linux1.krischik.com> Subject: Re: Idiom for a class and an object in Ada Date: Mon, 18 Oct 2004 15:40:58 -0400 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: <41741971$0$91011$39cecf19@news.twtelecom.net> Organization: Time-Warner Telecom NNTP-Posting-Date: 18 Oct 2004 19:28:49 GMT NNTP-Posting-Host: 21f9d5f8.news.twtelecom.net X-Trace: DXC=TLne:9]5fGE:9cegTIC^\@C_A=>8kQj6MhHXa^^g6TZDDFB78Rk0MABdYZAA8S:V?N X-Complaints-To: abuse@twtelecom.net Xref: g2news1.google.com comp.lang.ada:5412 Date: 2004-10-18T19:28:49+00:00 List-Id: "Martin Krischik" wrote in message news:9175719.eWmeGlFrVu@linux1.krischik.com... > Marin David Condic wrote: > >> Suppose I have a class with one or a limited set of objects. The objects >> are "global" in the sense that they hang around from program startup >> thru the entire life of execution. An example would be an A/D Converter >> class - My little control box might have 3 or 4 A/Ds in it - they're >> always there and I want the data associated with them to be static (not >> declared on the stack.) >> >> Question: What is the preferred Ada idiom for defining such a creature? See my previous post. You could either declare the known instances in the package itself: package AD_Converters is type AD_Converter (<>) is limited private; ... -- ops function Huey return AD_Converter; function Dewey return AD_Converter; function Louie return AD_Converter; end AD_Converters; The other possibility is to declare each function as a child: package AD_Converters.Huey_Converters is function Huey return AD_Converter; end; Alternatively, you can hide the package like this: function AD_Converters.Huey return AD_Converter; --spec private package AD_Converters.Huey_Converters is Huey : AD_Converter; .. --whatever else is necessary for the Huey object end; with AD_Converters.Huey_Conveters; function AD_Converters.Huey return AD_Converter is --body begin return Huey_Converters.Huey; end; Whether you declare all the objects up in the root package or as child functions is determined by whether your application always manipulates the objects as a group (that's the case in the genealogy example), and how many unique dependencies each object has (if the library units you need to make a Huey object are the same as the library units you need to make a Dewey object, then they might as well be declared together).