C
Chris Mullins
I tend to build high performance system, and when doing this stateless
programming is at a premium. This often means all of the public methods on a
class are defined as static.
I often find that the .Net framework has poor support for doing this.
Interface definitions don't allow static methods, so I can't build a
stateless contracts, and abstract classes cannot define a stateless method
as abstract. There's also no support for the concept of a virtual or
overridable stateless method. (Please, nobody tell me about vtables and
class instances - I know how it works).
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; }
}
In terms on a base class supporting shared methods, a similar approach would
be nice:
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?
programming is at a premium. This often means all of the public methods on a
class are defined as static.
I often find that the .Net framework has poor support for doing this.
Interface definitions don't allow static methods, so I can't build a
stateless contracts, and abstract classes cannot define a stateless method
as abstract. There's also no support for the concept of a virtual or
overridable stateless method. (Please, nobody tell me about vtables and
class instances - I know how it works).
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; }
}
In terms on a base class supporting shared methods, a similar approach would
be nice:
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?