This post originated from an RSS feed registered with .NET Buzz
by Darrell Norton.
Original Post: Why choose monostate over singleton?
Feed Title: Darrell Norton's Blog
Feed URL: /error.htm?aspxerrorpath=/blogs/darrell.norton/Rss.aspx
Feed Description: Agile Software Development: Scrum, XP, et al with .NET
A while back I was wondering what the pragmatic difference was between singleton and monostate. Recently someone named Ken left a comment that described why someone would use monostate over singleton other than personal preference.
To recap, the singleton pattern structurally enforces the fact that you can never have more than one instance of a class at a time, and it is obvious to the developers that they are dealing with a singleton. On the other hand, the monostate pattern enforces the behavior of a singleton without the structure of a singleton, e.g., the singleton behavior is encapsulated from the developers.
So why choose one over the other?
“If you plan on deriving classes from the singleton and you want those classes to be singletons, your better choice is monostate. That's because all classes derived from a monostate are monostates. Classes derived singleton classes are not singletons by default. You would have to add the static method and attribute to each derived class.”
This Blog Hosted On: http://www.DotNetJunkies.com/