<p>I've got a group of inter-related classes that are all overridden together to create a particular implementation. I'm wondering if it is a good idea to enclose the interrelated subclasses in a namespace.</p>

<p>For example purposes, consider the following namespaces and classes:</p>

<pre><code>namespace Protocol
{
  public abstract class Message { }
  public abstract class Driver { }
}
namespace Protocol.Tcp
{
  public class TcpMessage : Message { }
  public class TcpDriver : Driver { }
}
namespace Protocol.Ftp
{
  public class FtpMessage : Message { }
  public class FtpDriver : Driver { }
}
</code></pre>

<p>What is the best way to structure the namespaces? It seems unavoidable to expose the inheritance in the namespace since the base classes don't really belong in either the Protocol.Tcp namespace or the Protocol.Ftp namespace.</p>

[{'answer_id': 18616, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 4, 'selected': True, 'text': '<p>I think you are perhaps worrying too much!</p>\n\n<p>Does it make sense logically? Do you know where to find your code within the namespaces?</p>\n\n<p>I would much rather see a codebase like the above with a small number of classes, relevant to the name with a hierarchy, than one large namespace where everything is interrelated..</p>\n\n<p>Remember, namespacing is there for precisely this, to <strong>organise your codebase logically</strong></p>\n\n<p>What you have seems logical :)</p>\n\n<p>EDIT:</p>\n\n<p>As an example:</p>\n\n<pre><code>using System.Data;\nusing System.Data.Sql;\n</code></pre>\n\n<p>;)</p>\n'}, {'answer_id': 18625, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 0, 'selected': False, 'text': '<p>If this were me, I would define 2 namespaces:</p>\n\n<pre><code>Protocol\n</code></pre>\n\n<p>and</p>\n\n<pre><code>Protocol.Driver\n</code></pre>\n\n<p>Dividing the namespace like this separates your "library code" vs your "executable / test code."\nI also create my namespaces to match the directory structure; it will give logic to your programs structure and codefiles. (maybe you already do this...)</p>\n'}, {'answer_id': 124146, 'author': 'Ronnie', 'author_id': 193, 'author_profile': 'https://Stackoverflow.com/users/193', 'pm_score': 1, 'selected': False, 'text': "<p>The original tags show that this post is about C# - therefore multiple inheritance is an irrelevancy - you can't multiply inherit in C#.</p>\n\n<p>Maybe you should consider defining some interfaces that define what the basic contracts of a <code>Message</code> and a <code>Driver</code> are and then you may feel a little free-er to use the namespace structure to mimic the technology differences.</p>\n"}]
['https://Stackoverflow.com/questions/18608', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/327/']