tags:

views:

217

answers:

3

Hi Guys.

I have a singleton class called SingletonController1.

This SingletonController1 instantiates a bunch of others Singleton classes.

SingletonController1{
Authenticator - Singleton;
DBAccessor - Singleton;
RiskAccessor - Singleton;
}

My question is, what if I rework this design to:

   SingletonController2{
    Authenticator -non-singleton;
    DBAccessor -non-singleton;
    RiskAccessor -non-singleton;
    }

As long as SingletonController2 is the only class that instantiates those three non-Singleton classes, wouldn't this be functionally the same as the previous design?

Cheers

+1  A: 

Yes. These 2 designs accomplish the same thing, given your condition that no class other than Singleton2 instantiates Authenticator, DBAccessor and RiskAccessor.

Asaph
+4  A: 

Functionality will be the same, but flexibility much greater in the second case as the non-singleton classes can be reused elsewhere in your application/system. If they don't need to be singletons let they not be singletons.

quosoo
Thanks, my sentiments exactly.
CaptainHastings
+1  A: 

I think you are on the right track, but push it further. Go right back to your root of your program and you only need one singleton. There's a logical step after that too.

Tom Hawtin - tackline
Is that one singleton the application context?
HDave