From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Can't export object of private type
Date: 1999/02/28
Date: 1999-02-28T00:00:00+00:00 [thread overview]
Message-ID: <m3lnhi18jn.fsf@mheaney.ni.net> (raw)
In-Reply-To: F7p7Dq.DE1@syd.csa.com.au
nospam@thanks.com.au (Don Harrison) writes:
> Actually, I don't necessarily want to do that. What I'm really after
> is polymorphic singletons - objects that
>
> 1) Have only one instance
> 2) Are polymorphic
> 3) Are visible to clients
> 4) Can be called without a package prefix.
>
> I can acheive two or three, but not all four. :(
Hmmm. So you really do want a polymorphic singleton. I did just this
in some of my early posts to the patterns archive. See the stuff about
abstract factories and factory methods:
<http://www.acm.org/archives/patterns.html>
1) If you want one instance, make the type limited and indefinite. I
explain all this in my posts about singletons, also in the archives.
2) If you want polymorphism, then declare the type as tagged, and refer
to a class-wide object.
3) Export a function that returns a reference to the object (which is
declared in the body of the package).
4) Don't use a state machine package, use a type.
package Singletons is
type Root_Singleton_Type (<>) is abstract tagged limited private;
<primitive ops for Root_Singleton_Type>
type Singleton_Access is
access all Root_Singleton_Type'Class;
-- T'Class, to get dynamic dispatching
function Ref return Singleton_Access;
private
type Root_Singleton_Type is abstract tagged limited record...;
end Singletons;
package Singletons.Blue is
type Blue_Singleton_Type is new Root_Singleton with private;
<override primitive ops>
...
end;
with Singlestons.Blue;
package body Singetons is
Singleton : aliased Blue_Singleton_Type;
function Ref return Singleton_Access is
begin
return Singleton'Access;
end;
end Singletons;
You could even choose the specific type of the singleton at run-time;
this is precisely what I did in my abstract factory and factory method
examples.
next prev parent reply other threads:[~1999-02-28 0:00 UTC|newest]
Thread overview: 128+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <F7JoCB.JxB@syd.csa.com.au>
1999-02-24 0:00 ` Can't export object of private type Don Harrison
1999-02-24 0:00 ` Tom Moran
1999-02-24 0:00 ` Samuel Mize
1999-02-24 0:00 ` Tucker Taft
1999-02-25 0:00 ` Don Harrison
1999-02-25 0:00 ` Samuel Mize
1999-02-26 0:00 ` Don Harrison
1999-02-27 0:00 ` Nick Roberts
1999-03-01 0:00 ` Don Harrison
1999-03-01 0:00 ` Matthew Heaney
1999-03-01 0:00 ` Nick Roberts
1999-03-01 0:00 ` Nick Roberts
1999-03-01 0:00 ` Don Harrison
1999-03-02 0:00 ` Matthew Heaney
1999-03-03 0:00 ` Don Harrison
1999-03-03 0:00 ` Samuel Mize
1999-03-04 0:00 ` Don Harrison
1999-03-07 0:00 ` Ehud Lamm
1999-03-03 0:00 ` Robert A Duff
1999-03-04 0:00 ` Don Harrison
1999-03-04 0:00 ` Robert A Duff
1999-03-01 0:00 ` Don Harrison
1999-03-02 0:00 ` Matthew Heaney
1999-02-28 0:00 ` Matthew Heaney
1999-03-01 0:00 ` Nick Roberts
1999-03-01 0:00 ` Matthew Heaney
1999-03-01 0:00 ` Matthew Heaney
1999-03-02 0:00 ` Nick Roberts
1999-03-01 0:00 ` Samuel Mize
1999-02-25 0:00 ` fraser
1999-02-26 0:00 ` Don Harrison
[not found] ` <7b6nqe$75m$1@remarq.com>
1999-02-26 0:00 ` fraser
1999-02-27 0:00 ` Nick Roberts
1999-02-26 0:00 ` fraser
1999-03-01 0:00 ` Don Harrison
1999-03-01 0:00 ` Matthew Heaney
1999-02-26 0:00 ` Samuel Mize
1999-03-01 0:00 ` Don Harrison
1999-03-01 0:00 ` Matthew Heaney
1999-03-02 0:00 ` fraser
1999-03-03 0:00 ` Don Harrison
1999-02-28 0:00 ` Matthew Heaney
1999-02-28 0:00 ` Matthew Heaney
1999-02-25 0:00 ` robert_dewar
1999-02-26 0:00 ` Don Harrison
1999-02-26 0:00 ` robert_dewar
1999-02-26 0:00 ` bourguet
1999-02-26 0:00 ` Samuel T. Harris
1999-02-27 0:00 ` Simon Wright
1999-02-27 0:00 ` Jean-Pierre Rosen
1999-02-28 0:00 ` dewar
1999-03-01 0:00 ` bourguet
1999-02-26 0:00 ` dennison
1999-03-01 0:00 ` Stephen Leake
1999-03-01 0:00 ` Don Harrison
1999-03-01 0:00 ` robert_dewar
1999-03-03 0:00 ` Don Harrison
1999-03-03 0:00 ` robert_dewar
1999-02-27 0:00 ` Brian Rogoff
1999-03-01 0:00 ` robert_dewar
1999-02-28 0:00 ` Matthew Heaney [this message]
1999-03-01 0:00 ` Tom Moran
1999-03-02 0:00 ` Matthew Heaney
1999-03-02 0:00 ` Tom Moran
1999-03-02 0:00 ` Matthew Heaney
1999-03-02 0:00 ` Tom Moran
1999-03-02 0:00 ` Matthew Heaney
1999-03-02 0:00 ` nabbasi
1999-03-02 0:00 ` Matthew Heaney
1999-03-03 0:00 ` Don Harrison
1999-03-03 0:00 ` Single Extension; Polymorphic Arrays Nick Roberts
1999-03-03 0:00 ` Nick Roberts
1999-03-08 0:00 ` Matthew Heaney
1999-03-08 0:00 ` Tucker Taft
[not found] ` <m3ogm40wav.fsf@mheaney.ni.net>
1999-03-08 0:00 ` Nick Roberts
1999-03-08 0:00 ` Tucker Taft
1999-03-08 0:00 ` dennison
1999-03-09 0:00 ` Nick Roberts
1999-03-08 0:00 ` Nick Roberts
1999-03-03 0:00 ` Can't export object of private type Don Harrison
1999-03-03 0:00 ` Don Harrison
1999-03-03 0:00 ` Nick Roberts
1999-03-04 0:00 ` Don Harrison
1999-03-04 0:00 ` Nick Roberts
1999-03-04 0:00 ` robert_dewar
1999-03-05 0:00 ` Nick Roberts
1999-03-05 0:00 ` Robert A Duff
1999-03-05 0:00 ` Abstract Subprograms of Untagged Types Nick Roberts
1999-03-05 0:00 ` robert_dewar
1999-03-05 0:00 ` Tucker Taft
1999-03-05 0:00 ` Nick Roberts
1999-03-06 0:00 ` robert_dewar
1999-03-04 0:00 ` Can't export object of private type Nick Roberts
1999-03-08 0:00 ` Matthew Heaney
1999-03-09 0:00 ` Don Harrison
1999-03-09 0:00 ` Matthew Heaney
1999-03-09 0:00 ` Nick Roberts
1999-03-10 0:00 ` Don Harrison
1999-03-10 0:00 ` Matthew Heaney
1999-03-04 0:00 ` fraser
1999-03-09 0:00 ` Don Harrison
1999-03-08 0:00 ` Matthew Heaney
1999-03-08 0:00 ` Nick Roberts
1999-03-08 0:00 ` Matthew Heaney
1999-03-10 0:00 ` Don Harrison
1999-03-10 0:00 ` Matthew Heaney
1999-03-10 0:00 ` dennison
1999-03-10 0:00 ` robert_dewar
1999-03-10 0:00 ` dennison
1999-03-10 0:00 ` robert_dewar
1999-03-10 0:00 ` dennison
1999-03-11 0:00 ` dennison
1999-03-11 0:00 ` bill
1999-03-11 0:00 ` dennison
1999-03-11 0:00 ` Scott Ingram
1999-03-11 0:00 ` Larry Kilgallen
1999-03-12 0:00 ` dewar
1999-03-11 0:00 ` robert_dewar
1999-03-11 0:00 ` Don Harrison
1999-03-12 0:00 ` robert_dewar
1999-03-11 0:00 ` Don Harrison
1999-03-10 0:00 ` Robert A Duff
1999-03-10 0:00 ` robert_dewar
1999-03-10 0:00 ` dennison
1999-03-11 0:00 ` dennison
1999-03-03 0:00 ` Don Harrison
1999-02-28 0:00 ` Matthew Heaney
1999-02-28 0:00 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox