Search

Feb 16, 2007

Static holder types should not have constructors [Microsoft.Design]

I created class which has all the static methods, look at the following code there is no compilation error



public class ServerController
{
public static ArrayList GetHttpServers() { ... }
public static ArrayList GetXmlRpcServer() { ... }
}


But as fas as performance concern this is wrong!! Why?

Warning : Remove the public constructors from 'ServerController'.

But i havnt declare any constructor!!

I can explain you, the default constructor is created automatically so how to avoid this message.

Two ways, 1) Make default constuctor as private or 2) Or make your class static.

Now look at class again



public static class ServerController
{
public static ArrayList GetHttpServers() { ... }
public static ArrayList GetXmlRpcServer() { ... }
}


Simple right?

I also have delicious on Microsoft Design

No comments: