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:
- Potentially confusing for junior developers.
- Aliasing add overheads for anything which consumes the namespace.
- If aliasing is not used, confusing code for everyone.
Option2: Instead of using the namespace, name the class incorporating what are essentially namespace semantics. (OffensivePlay and DefensivePlay).
Option 2 Problems:
- Potential for long classnames. Ex: OffensivePresnapAdjustmentType
Embedding namespace semantics into class names leads to repetitive class names.
- OffensiveBasePlay
- OffensiveFormation
- OffensivePlay
- OffensivePlayer
- OffensivePackage
- OffensivePresnapAdjustment
- OffensivePresnapAdjustmentType
- (And Many More plus all of the defensive equivalents.)
- Less effective intellisense (Visual Studio)
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:
- Same problems as option 1.
- Introduce the complexity of multiple assemblies.
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?