[RFC][plugin]: make PluginObjectStore a singleton.

Denis Lila dlila at redhat.com
Thu Mar 31 12:29:00 PDT 2011

> I particularly like this comment ;) Do you have a source for this? I
> would prefer it if this was an actual class. It's not behaviourally an
> enum, so it should not be marked as such.

Effective Java, second edition.
I don't have the book with me, and I forget what Joshua Bloch's
arguments for enum singletons were (except for how much easier
the singleton property is to enfoce (which is more than enough
of a reason by itself, but there were others)), but they were
very good ones.

> It's not behaviourally an enum

I disagree with this. I agree that it's not behaviourally
a C++ enum, but Java enums are fundamentally different. In Java
an enum is simply a class with a compile-time constant number of
instances. That's exactly what a singleton is (except a singleton
is a special case of that, where that constant number is 1).

And besides, I see no practical problem with making this an
enum, but I do see practical benefits, so why not use it?
(unless someone else can see such problems, of course)


----- Original Message -----
> On 03/31/2011 03:03 PM, Deepak Bhole wrote:
> > * Denis Lila<dlila at redhat.com> [2011-03-31 14:54]:
> >> >  The attached patch does what the subject says.
> >> >
> >> >  Ok to push?
> >> >
> > Please rename the instance to INSTANCE and method to getInstance to
> > make
> > it clearer that it is a singleton in the caller as well.
> >
> I agree with what Deepak said.
> >> >  +// Enums are the best way to implement singletons.

> >> >  +enum PluginObjectStore {
> >> >  + THE_STORE;
> >> >
> Thanks,
> Omair

More information about the distro-pkg-dev mailing list