Lotus
Lotus

Reputation: 11

Design pattern: store globals in a single class

I want to store many "globals" into a single class. Is there any design pattern I can follow?

Upvotes: 1

Views: 163

Answers (5)

yegor256
yegor256

Reputation: 105133

If the "globals" are of the same type/interface I would suggest to consider Flyweight.

Upvotes: 0

Don Roby
Don Roby

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

Waquo
Waquo

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

T.E.D.
T.E.D.

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

Nathan Hughes
Nathan Hughes

Reputation: 96434

Sure, it's called Big Ball of Mud.

Upvotes: 2

Related Questions