Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:31:16+00:00 2026-05-28T05:31:16+00:00

Author post-edit: Chosen solution (Original question remains below this box) SUMMARY: You SHOULD NOT

  • 0

Author post-edit: Chosen solution

(Original question remains below this box)

SUMMARY: You SHOULD NOT name a class the same as its namespace. Therefore should a product name be used for the namespace or the main class?

Chosen solution: I decided to apply the product name to the namespace and add a suffix to the main class name (e.g., __Module).

Rationale: Visual Studio defaults to using the project name for the namespace, assembly name, as well as the actual deliverable .exe or .dll — These are the most visible items so I think it makes sense to name the namespace after my product name, then do as Jon Skeet recommends in his answer and name the main class as ___Main or __Program or __Module. No one right answer I suppose.


Original question:

I COMPLETELY GET IT– DON’T NAME A CLASS THE SAME AS ITS NAMESPACE!

This is almost a duplicate question… except I’ve spent hours reading articles (see below) and can’t find or think of a solution that seems right.

Say I have a product called the ACME Foobarinator. It has a couple related types (e.g., settings, enums) but not enough to call for any sort of namespace hierarchy.

It makes sense to create a single product namespace and throw everything into it:

namespace Acme.Web.Foobarinator
{
    public class Foobarinator { } // BAD! Same name as namespace!
    public class FoobarinatorInfo { }
    public enum Mode { Disabled, Enabled }
}

BAD!!! Both namespace and class name are the same!!

But, I’d also like the main class to be Foobarinator because it’s the trademark product name and I’d like consumers to use it by trademark name: var fb = new Foobarinator();

Option 1: Eliminate the product namespace, promoting all types to the parent namespace. But this pollutes the parent namespace with types that are specific to the product (and not necessarily all public types). As the product evolves, the pollution stands to increase!

namespace Acme.Web
{
    public class Foobarinator { }
    public class FoobarinatorInfo { }
    public enum FoobarinatorMode { Disabled, Enabled }
    // More pollution in future...
}

Option 2: Add needless suffix to the main class. But this obfuscates the product trademark name!

namespace Acme.Web.Foobarinator
{
    public class FoobarinatorMain { } // Not the name of the product!
    public class FoobarinatorInfo { }
    public enum Mode { Disabled, Enabled }
}

Option 3: Use child classes/types for the related types. However, encapsulating everything in one class eventually violates separation of concerns as the product evolves:

namespace Acme.Web
{
    public class Foobarinator
    {
        public class FoobarinatorInfo { }
        public enum Mode { Disabled, Enabled }
    }
}

YOUR THOUGHTS?

Where do I compromise?

Related questions and articles:

How to avoid having the same name for a class and it's namespace, such as Technology.Technology?

Should a class have the same name as the namespace?

Namespace with same name as a class name

Should a class have the same name as the namespace?

http://blogs.msdn.com/ericlippert/archive/2010/03/09/do-not-name-a-class-the-same-as-its-namespace-part-one.aspx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:31:16+00:00Added an answer on May 28, 2026 at 5:31 am

    I would use:

    namespace Acme.Web.Foobarinator
    {
        public class Program { } // The entry point
        public class FoobarinatorInfo { }
        public enum Mode { Disabled, Enabled }
    }
    

    or even:

    namespace Acme.Web.Foobarinator
    {
        public class EntryPoint { }
        public class FoobarinatorInfo { }
        public enum Mode { Disabled, Enabled }
    }
    

    The first is the Visual Studio default (at least for some project types) and the second makes it crystal clear what the role of the class is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this post the author recommends implementing a Wrapper for the session to ease
In this reddit blog post , the author talks about MD5ing the cache keys
Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
This post relates to WordPress and CIMY User Extra Fields. I do not think
I recently read a nice post on using StringIO in Ruby. What the author
I'm at a loss to for a solution to my comments section not showing
I have an edit page that fills the content with the original content from
In Wordpress , I want when the author of the post reading his post
This may sound like a noobish question (in fact, it is), but I can't
A WP user with the role Author can post articles. On the blog in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.