DDD ubiquitous language check
Identifiers in the core domain should use the Domain Model language — the ubiquitous language of Domain Driven Design (DDD): naming rigor, since software doesn't cope well with ambiguity.
Disabled per default: customize the core domain namespace name and the domain terms list. Mention singular and plural forms both if needed (e.g. Seat and Seats); see also the related rule Properties and fields that represent a collection of items should be named Items.
Relies on the NDepend API extension method ExtensionMethodsString.GetWords(this string identifier) that smartly extracts terms from identifiers.
Disabled per default: customize the core domain namespace name and the domain terms list. Mention singular and plural forms both if needed (e.g. Seat and Seats); see also the related rule Properties and fields that represent a collection of items should be named Items.
Relies on the NDepend API extension method ExtensionMethodsString.GetWords(this string identifier) that smartly extracts terms from identifiers.
How to fix
The rule lists the words not in vocabulary per violation. Either rename the code element or add the missing term(s) to the vocabulary list in the rule source.
CQLinq source
This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.
// <Name>DDD ubiquitous language check</Name>
// <Id>ND2018:DDDUbiquitousLanguageCheck</Id>
warnif count > 0
// Update to your core domain namespace(s)
let coreDomainNamespaces = Application.Namespaces.WithNameLike("TrainTrain.Domain")
// Update your vocabulary list
let vocabulary = new [] {
"Train", "Coach", "Coaches", "Seat", "Seats",
"Reservation", "Fulfilled", "Booking", "Book", "Reserve", "Confirm"
}.ToHashSetEx()
let technicalWords = new [] { "get", "set", "Get", "Set", "Add" }.ToHashSetEx()
let multiWordsVocabulary = vocabulary.Where(w => w.GetWords().Length >= 2)
// Append multi-words words in vocabulary
let multiWordsWords = multiWordsVocabulary.SelectMany(w => w.GetWords())
let vocabulary2 = vocabulary.Concat(multiWordsWords).ToHashSetEx()
let vocabulary3 = vocabulary2.Concat(technicalWords).ToHashSetEx()
from ce in coreDomainNamespaces.ChildTypesAndMembers()
let tokens = ce.SimpleName.GetWords().Select(w => w.FirstCharToUpper()).ToArray()
where !(ce.IsMethod && ce.AsMethod.IsConstructor) && // No vocabulary in ctor
!(ce.IsField && ce.AsField.IsGeneratedByCompiler) && // Remove compiler generated backing fields, their vocabulary is in property
!(vocabulary3.Any(vocable => tokens.Contains(vocable)))
let wordsNotInVocabulary = tokens.Where(w => !(vocabulary2.Contains(w) && string.IsNullOrEmpty(w))).ToArray()
select new { ce,
wordsNotInVocabulary = string.Join(", ",wordsNotInVocabulary)
}
//<Expl>
// The *{0}'s name* contains words like *{1}* which are not part
// of the domain vocabulary defined in this rule source code.
//</Expl>
//<Desc>
// Identifiers in the **core domain** should use the **Domain Model**
// language — the **ubiquitous language** of **Domain Driven Design (DDD)**:
// naming rigor, since software doesn't cope well with ambiguity.
//
// Disabled per default: customize the **core domain** namespace name and
// the domain terms list. Mention singular and plural forms both if needed
// (e.g. **Seat** and **Seats**); see also the related rule *Properties and
// fields that represent a collection of items should be named Items*.
//
// Relies on the NDepend API extension method
// **ExtensionMethodsString.GetWords(this string identifier)** that smartly
// extracts terms from identifiers.
//</Desc>
//<HowToFix>
// The rule lists the **words not in vocabulary** per violation. Either
// rename the code element or add the missing term(s) to the vocabulary list
// in the rule source.
//</HowToFix>
Open in the interactive Rules Explorer · All default rules
Naming Conventions: all 23 items
- Instance fields naming convention ND2000
- Static fields naming convention ND2001
- Interface name should begin with a 'I' ND2002
- Abstract base class should be suffixed with 'Base' ND2003
- Exception class name should be suffixed with 'Exception' ND2004
- Attribute class name should be suffixed with 'Attribute' ND2005
- Types name should begin with an Upper character ND2006
- Methods name should begin with an Upper character ND2007
- Do not name enum values 'Reserved' ND2008
- Avoid types with name too long ND2009
- Avoid methods with name too long ND2010
- Avoid fields with name too long ND2011
- Avoid having different types with same name ND2012
- Avoid prefixing type name with parent namespace name ND2013
- Avoid naming types and namespaces with the same identifier ND2014
- Don't call your method Dispose ND2015
- Methods prefixed with 'Try' should return a boolean ND2016
- Properties and fields that represent a collection of items should be named Items. ND2017
- DDD ubiquitous language check ND2018
- Avoid fields with same name in class hierarchy ND2019
- Avoid various capitalizations for method name ND2020
- Controller class name should be suffixed with 'Controller' ND2021
- Nested class members should not mask outer class' static members ND2022