July 07, 2004

C# Generics tricks

LazyLoader v0
http://scott.wisniewski-online.com/blog/archive/2004/04/29/158.aspx

LazyLoader v1
http://weblogs.asp.net/jaybaz_ms/archive/2004/04/30/124229.aspx

LazyLoader v2 (+delegate and cleanups+ILock)
http://weblogs.asp.net/jaybaz_MS/archive/2004/05/06/127489.aspx

LazyLoader v3 (+IWeakReference+IOptional)
http://weblogs.asp.net/jaybaz_ms/archive/2004/05/07/128185.aspx

Generic Singleton
Singleton mixin?

http://www.codeproject.com/useritems/objectguard.asp
The Code Project - Simplifying Exception-Safe Code, Generics Style

C5 library for .Net
http://www.itu.dk/research/c5/

Cyrus blog http://weblogs.asp.net/cyrusn/

http://weblogs.asp.net/scottdensmore/archive/2004/05/25/140827.aspx Why Singletons are Evil

Generics + anonymous delegates in Collection classes
http://blogs.msdn.com/kcwalina/archive/2004/06/22/162533.aspx

// Impossible approach
Public ISingleton {
Private static T instance = null;
Private constructor…

Public T GetInstance() {… new T(); … }
}


// basic approach
// problem is the actual class T doesn't need to have a protected constructor, which means
//
there is a risk anybody can instanciate it...
Public Singleton {
Private static T instance = null;
Private Singleton(); // constructor
Public T GetInstance() {… new T(); …}
}


// No constructor approach
// Interfaces can't specify constructors
// Let's use another method to do the construction
Public ISelfBuilder {
// Is pretty weird because makeNew is just a renamed constructor….
Private static T makeNew();
}

Public singleton> {
Private static T instance = null;
Public T GetInstance() {… T.makeNew();…}
}

Posted by Julien. Permalink | TrackBack
Comments
Trackbacks
Post a comment









Your email address won't be published on the site if you also input a URL.

Remember personal info?