views:

49

answers:

1

I have a question regarding naming conventions in C# that I don't think are covered in either the majority of the previously asked questions or the usual resources like the MSDN Naming Guidelines. The majority of existing naming conventions focus on frameworks and things to be consumed by other classes. This may be a bit different.

What do you name the class where Main() resides? And how does it relate to its superclass?

Let's say you're a fledgling programmer and you create a small application much like this site. You might do something like this.

// the title of the class happens to be the title of the project

namespace FogCreek {
  public class StackOverflow {
    public static Main() { ... }
  }
}

But then you decide to refactor your innards as you grow and create more Stack sites, each one occopying their own namespace.

namespace FogCreek.StackSites.StackOverflow {
  public class WhatDoICallThis : StackExchangeSite {
    public static Main() { ... }
  }
}

// elsewhere in another project...

namespace FogCreek {
  public class StackExchangeSite {
    ...
  }
}

I'm hesitant to call it StackOverflow because it's full name be FogCreek.StackSites.StackOverflow.StackOverflow. Isn't that a bit redundant?

Also, should StackExchangeSite be in its own namespace within FogCreek? Or should it be "higher than" the projects that derive from it?

Company.Foobar.Widget
-> Company.Foobar.Widget.RoundWidget
-> Company.Foobar.Widget.SquareWidget

vs

Company.Foobar.Widget.BaseWidget
-> Company.Foobar.Widget.RoundWidget
-> Company.Foobar.Widget.SquareWidget

I don't favor the second option because I don't recall any extendable classes that use the word "Base".

+5  A: 

I think that you should rather leave it as is (typically called Program) and instead favor composition over inheritance.

The entry point it a static method, so there's absolutely no reason to create an inheritance tree that involves the class holding the Main method.

Mark Seemann