| Sean Feldman's profileברוכים הבאיםPhotosBlogLists | Help |
|
27/07/2007 Head First - Object-Oriented Analysis and DesignRead this one when done with Design Patterns book 11/07/2007 Generic Event HandlerJP Boodhoo has showed a nice way of using generic event handler: http://www.jpboodhoo.com/blog/LeveragingTheEventHandlerDelegateMoreEffectively.aspx PS: Interestingly, I was going through Microsoft WCSF and the ObjectBuilder they have there is using a type called DataEventArgs, which is the same JP proposed. 04/07/2007 Head First Design Patterns Book
SingletonDefinition of a singleton is simple. So is the usage, but when it comes to testing/mocking/dynamically replacing it - that's a pain. While investigating MVP pattern, and reading materials from Jeremy D. Miller, I ran into on of his blogs about Singleton. It inspired me to adopt the approach and share the thoughts. Singleton (noun) - single card of a particular suit (Cards); individual occurrence or item, single instance or thing I liked the 1st definition - a single card of particular suit. In real project a singleton is one and only, but from time to time, you need to replace it with a different implementation. So this is what I learned:
public interface ISingleton public class Singleton : ISingleton { private static readonly Singleton _instance; private static readonly string _testData = "Unique data for this variation of singleton"; static Singleton() { _instance = new Singleton(); } private Singleton() {} public static Singleton Current { get { return _instance; } } #region ISingleton Members public string DoThisAndThat() { return _testData; } #endregion } Usage: ISingleton current = Singleton.Current; Console.WriteLine(current.DoThisAndThat()); Better approach would be to have a factory that would return the Right singleton as a ISingleton, based one what is registered/required. One of the probably the best things about it is the fact that now it can be mocked as well. |
|
|