Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Wednesday, December 31, 2008

Nontransitive generic interfaces

We're pretty busy racing to a deadline, so I don't have a great deal of time to dig into this. I just stumbled across a C# feature that works differently than I would have guessed. Check out the following code.


public class test
{
   public void doTest()
   {
      Interface1<object> win = new Class1<object>();
      Interface2 fail = new Class1<object>();
   }
}

public interface Interface2 : Interface1<object>
{
}

public interface Interface1<t> where T : class
{
}

public class Class1<t> : Interface1<t>
   where T : class
{

}


All I am really after is for Interface2 to act as an alias for Interface1 and hide the generic declaration bits. Well ... here it is. Maybe I'll come back later if I figure out a solution.

Thursday, October 2, 2008

Monostate

Spent a little bit today learning about Monostate and why some folks think the Singletons are the really bad.
  1. http://jeremyjarrell.com/archive/2008/04/21/88.aspx
  2. http://codebetter.com/blogs/jeremy.miller/archive/2005/08/04/130302.aspx
  3. http://c2.com/cgi/wiki?MonostatePattern
Today I came across two Jeremy Miller posts (second one in list) concerning two completely different things. I think I will keep track of this dude. His comments about the Singleton constructor pattern make me chuckle. I wish I had known about it when he wrote it. At almost exactly the same time, my more aggressive peers at a former employer demanded that many particular types of services MUST be implemented as singletons and the instantiation pattern MUST follow exactly the code that Jeremy is deriding in his post. I won't go so far as to say that only a Sith speaks in absolutes, but I will say that the words MUST and ALWAYS when applied to software architecture tend to make me bristle.