+1.916.577.1977 | Downloads | Buy | Register | Login
 Search  
Wednesday, August 20, 2008
Search Blogs
 

Available Blogs
 

Previous Blogs
 

Technorati
 
More blogs about coversant.

About Coversant
 

Wish List: Static Interfaces and Abstract Static Methods for C#
 
Location: BlogsMullin' with Mullins    
Posted by: Chris Mullins 8/20/2006
I tend to build high performance system, and when doing this stateless programming is at a premium. To let the compiler help me guarantee that my methods are stateless, I tend to build mostly static functions and classes.

However, static (or Shared in VB) as a keyword doesn't go very far. You can still build in state - after all, there are static constructors, static properties, static member variables, thread static variables, and other easy to use trick to add state into a static class or method.

I continually find myself wishing the .Net Framework had more support for statless programming. Microsoft discovered back in the days of DCOM that stateless is the only way to scale, as it avoids the entire affinity problem.

As an architect and systems designer, I want to build frameworks that establish contracts with regard to state. I want to know that the person implementing a given contract has to do so in a statless manner.

The classic way of establishing a contract in .Net is through an Interface. Interface definitions however, don't allow static methods, so I can't build a stateless contracts. No dice here.

The other means of establishing a contract is through abstract classes. Unfortunatly a static method can't be defined as abstract. There's also no support for the concept of a virtual or
overridable stateless method. I understand the complexities involved, and how vTables and such are implemented, but at the end of the day, I want statless contracts.

What I would like to see, in terms of an Interface, I would like code to end up looking like this:
public interface IExample
{
static int SomeFunction(int x, int y);
}

public class ConcreteClass : IExample
{
public static int SomeFunction(int x, int y)
{ return x + y; }
}
As it is common, everything an Interface can do should be supported by the Class syntax as well. Base Classes should support abstract static methods, and inherited classes should be implement and/or override as appropiate.
public abstract class ExampleBase
{
public static abstract int Sample(int x, int y);
}
public class ExampleConcrete : ExampleBase
{
public static override int Sample(int x, int y)
{ return x + y; }
}

It seems as if each of these features would enable a richer development environment for building stateless components. The lack of this features seems to often affect class design, even within the MS framework.

For example, the data layers generated by the .Net 2.0 Data Adapter class don't use stateless data methods, and yet most hand-rolled data layers do.

Anyone have any suggestions of a solid way to do contract based development and still enforce statless programming?
Permalink |  Trackback

Comments (1)  
Re: Wish List: Static Interfaces and Abstract Static Methods for C#    By kyes on 6/7/2008
thx for the code.

--
Digital Frames


©2008 Coversant, Inc. | Privacy Policy | About Coversant | Contact Info