Note that there are some explanatory texts on larger screens.

plurals
  1. POThe C# namespace and class/sub-class naming conventions when the top namespace contains the base class and inner namespaces contain sub-classes
    text
    copied!<p>I'm trying to design a class library for a particular engineering application and I'm trying to ensure that my class &amp; namespace naming conventions make sense. </p> <p>I have the following situation:</p> <pre><code>namespace Vehicle{ class Wheel{...} //base class for Wheel objects class Engine{...} //base class for Engine objects ... namespace Truck{ class Wheel: Vehicle.Wheel{...} //Truck specific Wheel object class Engine: Vehicle.Engine{...} //Truck specific Engine object ... } namespace Car{ class Wheel: Vehicle.Wheel{...} //Car specific Wheel object class Engine: Vehicle.Engine{...} //Car specific Engine object ... } ... } </code></pre> <p>The code gets used in ways that all of these classes will need to be referenced from within the same scope. The following situation would be likely:</p> <pre><code>... Vehicle.Wheel.DoSomething(); Vehicle.Truck.Wheel.DoSomething(); Vehicle.Car.Wheel.DoSomething(); ... </code></pre> <p>Under these circumstances, am I better off giving the classes more specific names</p> <pre><code>namespace Car{ class CarWheel: Vehicle.Wheel{...} //Car specific Wheel object ... } </code></pre> <p>or leave the naming as shown in the first example and rely on the information that is encoded in the namespace for clarity? Under the latter approach, I assume I would want to utilize alaising for clarity in the code that makes use of this library, corret?</p> <p>It seems redundent to have:</p> <pre><code>Vehicle.Car.CarWheel </code></pre> <p>or</p> <pre><code>Vehicle.Truck.TruckEngine </code></pre> <p>but I also want to have very descriptive and specific class names.</p> <p>Philosophically, what I'm asking is whether or not to include the namespace as a part of the class name when considering if a class name is descriptive enough.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload