Alex Rivera | Logout

Alternatives to Singletons

Asked 2011-09-01T07:12:18.963
16

This is related to: What is so bad about Singletons

Can you give me some examples where Singletons can be avoided using other techniques? I need to use this in C++ so you can give examples with C++ specific techniques.

To be more clear: How you would implement a file manager, resource manager, log manager, etc without singletons.

Edit
Report

1 Answer

7

How you would implement a file manager, resource manager, log manager, etc without singletons.

By not making them singletons and passing them down the call-tree and object-nets as parameters and references instead.

As a general rule: If you only need n instances, then create just n instances.

Or: If two instances of a well-designed class do not clash without breaking the class' contract, do not make it a singleton.

answered 2011-09-01T08:05:27.700

Your Answer