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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Idiom for a class and an object in Ada Date: Mon, 18 Oct 2004 14:14:09 +0200 Organization: AdaCL Message-ID: <9175719.eWmeGlFrVu@linux1.krischik.com> References: Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1098109195 05 32207 z-oqXVvJmH3bShkW 041018 14:19:55 X-Complaints-To: usenet-abuse@t-online.de X-ID: rBNscgZBrePJWY7Me79bDclq6Q5aC4V8DL-Lb8G88CmBauR1wSbCEs User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:5401 Date: 2004-10-18T14:14:09+02:00 List-Id: 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 -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com