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!prodigy.com!newshosting.com!nx02.iad01.newshosting.com!38.144.126.100.MISMATCH!feed5.newsreader.com!newsreader.com!border2.nntp.dca.giganews.com!nntp.giganews.com!elnk-atl-nf1!newsfeed.earthlink.net!stamper.news.atl.earthlink.net!newsread3.news.atl.earthlink.net.POSTED!d9c68f36!not-for-mail From: Marin David Condic User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Idiom for a class and an object in Ada References: <9175719.eWmeGlFrVu@linux1.krischik.com> In-Reply-To: <9175719.eWmeGlFrVu@linux1.krischik.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Tue, 19 Oct 2004 12:59:26 GMT NNTP-Posting-Host: 209.165.3.210 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.atl.earthlink.net 1098190766 209.165.3.210 (Tue, 19 Oct 2004 05:59:26 PDT) NNTP-Posting-Date: Tue, 19 Oct 2004 05:59:26 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:5449 Date: 2004-10-19T12:59:26+00:00 List-Id: So you would do something that looked like this: package AD_Converter_Class_And_Objects is type AD_Converter is tagged private ; procedure Some_Op (AD : in out AD_Converter) ; AD_Number_1 : AD_Converter ; private --stuff end AD_Converter_Class_And_Objects ; Similarly if I had a half-dozen of these puppies? If I had only one, you'd want to hide it in the package body and make the package be an object instead of a class? Would there be a reason to prefer making a child package to contain one or more objects of the class? Or a separate child package for each object? There could be plusses and minuses to any given approach. I'm mostly wondering what most Ada programmers prefer or tend to use. MDC Martin Krischik wrote: > 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? >> >>I have a package that defines the class - that contains the tagged type >>and any methods. I might: >> >>a) Declare the objects within that "class" package > > > Yes, within the class body only. > > >>b) Declare the objects within some child package of the class package > > > If there are a lot of static data, use a private package. > > For both: When multi tasking is an issue use a protected type to secure > access to the data. > > >>c) Declare the objects in some global "Here's all my static data" >>package (not very tidy) > > > No. > > >>d) Declare the objects in the main program (not good if they are >>accessed by more than one task and also a kind of dumping ground) > > > No as well. Each package has it > > >>Does anybody have an opinion or experience with doing this? I know what >>I've done in the past, but I'm curious if there is any preferred method >>or idiom for this in the OO paradigm as applied to Ada? > > > If you truly thing about OO you would us a singelton class. You know a class > where only one instance exists. Within the singelton class (package body) > you can either use class data or static data. It would not matter since is > is all hidden inside the package body. > > With Regards > > Martin > > -- ====================================================================== Marin David Condic I work for: http://www.belcan.com/ My project is: http://www.jsf.mil/NSFrames.htm Send Replies To: m o d c @ a m o g c n i c . r "Power corrupts. Absolute power is kind of neat" -- John Lehman, Secretary of the Navy 1981-1987 ======================================================================