For many cases a static class is probably fine. It's easy to write, easy to
read, and easy to explain.

The advantage to the singleton pattern is that it gives you access to all of
the object oriented design paradigms/technologies that come with a modern
object oriented language.

An obvious singleton application would be to define a static interface to
the root of an abstract object hierarchy, and use an inherited class as your
implementation. You might also want to replace the instance during the
lifetime of the application (you might be caching the instance based on some
sort of CacheDependency), or provide quasi-singletons
(per-thread/per-session, etc).

You can also run into problems when trying to do generic programming in the
.net framework because you can't access static members of a templated type.
Sometimes it helps to use the singleton pattern to provide member-functions
to call in template situations (then again, if you're using a static class,
you wouldn't be doing generic programming based on it, and you don't have
this problem).

Anyway, the singleton pattern adds power, at the cost of complexity to the
implementor. As far as the user is concerned, if the added internal
complexity allows for a simpler or more effective/customizable interface, it
 can be worth it (you're only implementing it once... it may be reused for
years, at leasy that's what the OOP people would say).


Luke

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to