11609

Namespace and Class Naming Best Practice in Atypical System

Question:

There is a lot of good guidance out there on best practices for namespace and class naming in typical systems.

I am modeling a system which introduces a problem not addressed by the available guidance (at least I am not able to find it). The system naturally has several classes which would share the same name.

For simplification, I will use a domain example that captures the essence of the problem .

Option 1: I could use namespace and namespace aliasing to differentiate the classes in code. Classes would be named without concern for duplication across the namespace.

Football.Offense.Tactics

class Play { }

Football.Defense.Tactics

Class Play { }

using Offensive = Football.Offense.Tactics

using Defensive = Football.Defensive.Tactics

{

Offensive.Play offensivePlay = new Offensive.Play();

Defensive.Play defensivePlay = new Defensive.Play();

}

Option 1 Problems:

<ul><li>Potentially confusing for junior developers.</li> <li>Aliasing add overheads for anything which consumes the namespace. </li> <li>If aliasing is not used, confusing code for everyone.</li> </ul>

Option2: Instead of using the namespace, name the class incorporating what are essentially namespace semantics. (OffensivePlay and DefensivePlay).

Option 2 Problems:

<ul><li>Potential for long classnames. Ex: OffensivePresnapAdjustmentType</li> <li>

Embedding namespace semantics into class names leads to repetitive class names.

<ul><li>OffensiveBasePlay</li> <li>OffensiveFormation</li> <li>OffensivePlay</li> <li>OffensivePlayer</li> <li>OffensivePackage</li> <li>OffensivePresnapAdjustment</li> <li>OffensivePresnapAdjustmentType</li> <li>(And Many More plus all of the defensive equivalents.) </li> </ul></li> <li>Less effective intellisense (Visual Studio)</li> </ul>

Option 3: Create two assemblies - Football.Offense and Football.Defense. (This is the same as option 1 with the potential for an even cleaner separation)

Option 3 Problems:

<ul><li>Same problems as option 1. </li> <li>Introduce the complexity of multiple assemblies.</li> </ul>

I am tending towards the first or 3rd option, but I don't have enough practical experience to know if a decision is going to lead to a lot of tedious namespace and class name refactoring in a future release.

I want to architect the namespace and properly name the classes to withstand the test of time over several major releases.

What are your thoughts on best practices in this situation?

Answer1:

You don't really understand namespaces I think is the problem.

How are plays in defensive tactics and offensive tactics actually a different type of object.

Some plays are defensive tactics some are offensive. I.e. defensive and offensive is a property of the play not the other way around.

Namespaces are simply <strong>organisational units.</strong>

You may use a name space for a file loader and another for a tactics engine.

Why not just have an IPlay interface with a play method... and some kind of tactics classes that implement them. I don't get why you want namespaces at all or want to invert the object structure that would naturally work.

You are trying to make the more specific occupy the position of the more general in a hierarchy imo. Hence why you are feeling the pain.

Recommend

  • SQL Rows into Columns
  • Retrieve all content between a closing and opening html tag using Beautiful Soup
  • protobuf-net not deserializing array of sbyte
  • phpexcel - using it with excel template (chart goes missing) php
  • Wants to get list of all junior doctors working under senior doctor and vice versa?
  • Filter datatable column using dropdown
  • How to set up multiple aliased joins between two models?
  • Mvapich2 buffer aliasing
  • do.call to build and execute data.table commands
  • (How) am I supposed to destroy a uv_async_t?
  • White spots when drawing mutliple lines close to each other
  • In Scala, why can I use `Unit` as return type here?
  • Splitting a csv file into panda dataframe by multiple columns
  • How to upload video to Vimeo through their api?
  • Best method for parsing date formats during import datas
  • Making public posts via Facebook App?
  • What is the difference between Google Developers Console project and a Google **Play** Developers Co
  • Will jQuery ever leverage HTML5 technologies?
  • What's wrong when I try to install ADT on Eclipse?
  • Can service-worker stop push notification sent by GCM api?
  • Why do native C++ projects have a TargetFrameworkVersion?
  • Generic collection in generic class
  • Binding Dynamic URL to FB like Button in angular2
  • Connection pooling with URLConnection?
  • Google Places API - Get more than 10 photos from Details Response?
  • Android Oreo JobIntentService Keep running in background for Android 7 &below and crashing often
  • Weird LEFT OUTER JOIN on Includes eager loading of rails 3
  • Connecting Google Cloud SQL with Wordpress on Google Compute Engine
  • How to make SASS put relative paths in its output
  • Django model inheritance, filtering models
  • Low TTL with Leveled Compaction, should I reduce gc_grace_seconds to improve read performance withou
  • How can I set a binding to a Combox in a UserControl?
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • x64 applications using gdi+: what are the consequences on performance?
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • Problems to linebreak with an int in JLabel
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • UserPrincipal.Current returns apppool on IIS