Fabrice's weblog

Tools and Source

News

My .NET Toolbox
An error occured. See the script errors signaled by your web browser.
No tools selected yet
.NET tools by SharpToolbox.com

Read sample chapters or buy LINQ in Action now!
Our LINQ book is also available on AMAZON

.NET jobs

Emplois .NET

Tuneo

ASP.NET Hosting transatlantys

Contact

Me

Others

Selected content

Design Patterns potential hazards

As Object Oriented Programming fans, you all know Design Patterns and rely on them for your designs.

This post by Chris Johnson about a potential hazard with the Singleton pattern is a good reminder that Design Patterns are not magical recipes. They can be sources of problems like any other piece of code if not implemented carefully.

In the comments, people linked to interesting articles about the correct implementation of the Singleton pattern in C#:

Better check your implementations accordingly...

As Mark Townsend says in his article: Design patterns are very useful software design concepts that allow teams to focus on delivering the very best type of applications, whatever they may be. The key is to make proper and effective use of design patterns.

Comments

Evain Jb said:

# June 10, 2004 9:34 AM

AT said:

Okey. Okey.
Now everybody know how to create correct Singleton Pattern in C#.

But how about another problem - currently lifetime for Singleton is infinite.
And in case if it was used only once - it will remain in memory for-ever.

But in case if Singleton used soly as cache for data what you can recreate (for example pre-parsed configuration file data) you can save memory.

How to create SingletonCache pattern with memory/resources freed if it's not used for long time ??

# June 10, 2004 10:23 AM

Fabrice said:

Why not put your singleton in the Cache instead of a static variable?
System.Web.Caching.Cache can be used even outside of ASP.NET applications.
# June 10, 2004 10:28 AM

TrackBack said:

# June 10, 2004 11:40 AM

TrackBack said:

# June 13, 2004 11:20 AM

TrackBack said:

# June 14, 2004 11:37 AM

TrackBack said:

# July 7, 2004 4:12 PM

TrackBack said:

# July 27, 2004 5:11 AM

Fabrice's weblog said:

I was playing with services and containers, as part of my implementation of Inversion of Control . All

# November 12, 2009 7:01 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)