comp.lang.ada
 help / color / mirror / Atom feed
From: Brad Moore <brad.moore@shaw.ca>
Subject: Re: What is your opinion on Global Objects?
Date: Thu, 20 Nov 2014 20:00:41 -0700
Date: 2014-11-20T20:00:41-07:00	[thread overview]
Message-ID: <tVxbw.738406$Lj7.82862@fx22.iad> (raw)
In-Reply-To: <8561e9omp7.fsf@stephe-leake.org>

On 2014-11-20 9:34 AM, Stephen Leake wrote:
> If you can really, truly, absolutely guarrantee that you will _never_
> need two different copies of the data structure, then the singleton
> pattern makes sense (data in a single variable in a package body).
>
> If you ever need two different copies of the data structure, then you
> need to pass it around in parameters.

Not entirely true. Another possibility is to use generic packages.
Each instantiation of the generic could contain an independent copy of 
the data structure. One can select which object to operate on by 
selecting and using the generic instantiation of interest.

I think that generally this is not a good design, but I have seen it 
used in a fair bit in practice. For this case, I generally prefer to see 
a type declared in the visible part of the package that can is passed as 
a parameter to the subprograms declared in the package.

This is generally more flexible. One can use the object as a component 
in a larger record structure, or protect access to certain objects, by 
wrapping them in a protected object.

Otherwise, if the singleton is buried in a package body without any 
protection around the object, if someone wants to use the instantiation 
from multiple tasks, the usage can be unsafe or error prone and messy,
and the object does not have composability.

However, there are probably certain abstractions where that approach 
makes sense.

For the singleton case, I tend to prefer the object inside the body of 
the package approach though.

Brad


  parent reply	other threads:[~2014-11-21  3:00 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-18  1:36 What is your opinion on Global Objects? Hubert
2014-11-18  2:52 ` Jeffrey Carter
2014-11-18  3:08   ` Hubert
2014-11-18  3:16     ` Shark8
2014-11-18  5:09     ` Jeffrey Carter
2014-11-18 11:23     ` Brian Drummond
2014-11-19  2:50       ` Hubert
2014-11-19  3:03         ` Jeffrey Carter
2014-11-19  9:13           ` Hubert
2014-11-19 10:22             ` J-P. Rosen
2014-11-19 17:37             ` Jeffrey Carter
2014-11-20 16:34         ` Stephen Leake
2014-11-20 21:11           ` Adam Beneschan
2014-11-21 15:25             ` Stephen Leake
2014-11-21 21:53             ` Randy Brukardt
2014-11-21  1:25           ` Hubert
2014-11-21  3:00           ` Brad Moore [this message]
2014-11-19 10:11   ` Jacob Sparre Andersen
2014-11-20  6:21     ` Hubert
2014-11-18  8:54 ` Dmitry A. Kazakov
2014-11-20 20:33 ` sbelmont700
2014-11-20 21:35   ` J-P. Rosen
2014-11-21  1:02     ` sbelmont700
2014-11-21  1:31       ` Hubert
2014-11-21  9:01     ` Dmitry A. Kazakov
2014-11-22  7:46       ` J-P. Rosen
2014-11-22  9:02         ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox