Reputation: 11
I want to store many "globals" into a single class. Is there any design pattern I can follow?
Upvotes: 1
Views: 163
Reputation: 105133
If the "globals" are of the same type/interface I would suggest to consider Flyweight.
Upvotes: 0
Reputation: 41135
What you're describing is pretty much the Multiton, which is closely related to the Singleton.
It manages a map of named instances as key-value pairs.
It has the same drawbacks as a singleton, and should be avoided unless you really need it. And you probably don't really need it.
Upvotes: 0
Reputation: 840
You may be looking for a service locator, or dependency injection.
Martin Fowler on both: http://martinfowler.com/articles/injection.html
Upvotes: 1
Reputation: 44804
Typically this is what the singleton pattern is used for.
The singleton is probably both the most popular, and most reviled pattern.
Upvotes: 2