Class Design Implementation Specification
Purpose
This validator enforces consistency between the class model in the unit design and the class model extracted from the implementation.
It shall make sure that every class and free function, as well as every class member, method, enum literal, type alias, and relationship modeled in the unit design, exists in the implementation and is compatible with it.
Implementation-only entities and members are allowed. The unit design is the validated contract.
What is Validated
The validator compares unit design class diagrams with implementation class diagrams produced by the C++ parser. It receives two indexed class-diagram inputs:
Input |
Source |
Meaning |
|---|---|---|
|
|
Required class model from the unit design |
|
C++ parser class diagram FlatBuffers from |
Observed class model from implementation code |
Entity Presence and Type Consistency
Every entity in the unit design class diagram must have a corresponding entity
in the implementation class diagram. Matching entities must have the same entity
type.
(Requirement: Tools.ClassDesignImplementationEntityConsistency)
This item covers entity matching and entity type only. The consistency of data contained by a matched entity is covered by the following type alias, variable, method, enum literal, relationship, and template parameter items.
If the same class ID is declared more than once across the unit design’s input
class diagrams (e.g. an overview and a detail .puml file), the declarations
merge: members, type aliases and relationships of all declarations are united,
and a member redeclared identically is kept once. Methods are the same member
when name, parameter types and const agree, so data() and data() const
are two overloads; type spellings are compared normalized, as in the
design-to-implementation comparison. A member redeclared with a different
definition, and a different entity type, stereotype, template parameter list
(one that only adds inferred parameter packs is the same) or enum literal list
(declare all literals in one diagram), are failures naming both conflicting
source locations. The id alone identifies a class, so declarations under
different spellings or aliases merge, as do specializations of one template,
whose ids share the base name. Ids differing only in case are reported as a
duplicate class. A member merged from another diagram is reported at its own
source location.
(Requirement: Tools.ClassDesignImplementationDeclarationMerge)
' PlantUML class diagram
package vehicle {
class "Transport"
}
// implementation C++ code
namespace vehicle {
class Transport {}
}
Template Parameter Consistency
Template parameters modeled on unit design entities and methods must match the
template parameters on the corresponding implementation entities and methods.
(Requirement: Tools.ClassDesignImplementationTemplateParameterConsistency)
For classes, methods, and free functions:
A nonempty design declaration parameter list may omit trailing implementation parameters; defaults are not required or inspected. Extra design entries and skipped intermediate positions are not allowed.
Explicit parameters match by position, kind, and pack marker; non-type types follow Type Normalization. Template-template lists follow these rules recursively.
Omitted design names are unconstrained; explicit names must match. An absent (
None) list matches onlyNone, and an explicit empty list only an explicit empty list; neither is a wildcard.Method/free-function template declarations are checked after selection under Overload Group Matching.
Specialization exception: implementation partial and explicit full specializations are matched by fully qualified base name only. Their class template parameters and specialization arguments are not validated against the design. This exception does not apply to method template parameters. A debug diagnostic explains when the class template-parameter check is skipped.
When matching partial or explicit full specializations exist, a matching primary template is included in implementation consistency checks only if its template parameters match the design. This allows rejection-only primary templates to be excluded from a specialization’s interface contract; the validator does not determine whether a primary template serves that purpose. Without matching specializations, the primary template is checked normally, including template-parameter mismatches. Ordinary non-template classes are not subject to this primary-template filtering rule.
Notation: type, non-type, and template-template parameters support optional
names and packs: typename... Ts, int... Ns, and
template<typename> class... Cs. class and typename are interchangeable for
type parameters and template-template parameter tails. Packs precede explicit
names (typename Ts... is unsupported). Legacy T and Ts... denote type
parameters; unnamed non-type parameters require built-in or unambiguous compound
types such as int, std::size_t, or int*.
Scope: this is a modeling subset, not C++ declaration validation. Defaults, constraints, and complex declarators are unsupported; type lookup and semantic validity remain the C++ compiler’s responsibility. An unsupported template list in a quoted name produces no template parameter metadata.
' PlantUML class diagram
class Repository<T> {
+ FindById<Key>(id: Key) : T
}
// implementation C++ code
template <typename T>
class Repository {
template <typename Key>
T FindById(Key id);
}
Specialization Interface Matching
A quoted class name may describe a partial or explicit full specialization. Its trailing template arguments are removed from the design entity ID; an alias does not change that ID.
The declared interface is checked against every implementation partial or explicit full
specialization with the same fully qualified base name, without comparing its
class template parameters or specialization arguments. On the implementation side,
that base name is the qualified ID after removing only its final template-argument
list: Outer<Policy>::Box<int> matches Outer<Policy>::Box, not Outer::Box.
The raw design <…> text is not retained for argument comparison, so a typo such as
<ReturnTyp(ArgTypes...), Capacity, Alignment> or an unrelated list such as
<int, X> does not cause a specialization-argument mismatch. A debug diagnostic
identifies each skipped class template-parameter check and explains this
base-name-only matching limitation.
The design therefore defines one shared contract, not separate contracts per specialization. Multiple patterns resolve to the same ID and follow the declaration-merge rules above; conflicting declarations fail before implementation comparison.
For example, a design entity Box is checked against both Box<int> and
Box<double> explicit full specializations. A design label Box<int> still
resolves to the base ID Box; it does not select only the int specialization.
Each specialization must satisfy the shared member and method contract, including
method template parameters. No template-argument substitution is performed when
comparing member or method types.
Explicit instantiation definitions (template class Box<double>;) and declarations
(extern template class Box<float>;) reuse an existing template implementation;
they do not define independent interfaces. The C++ extractor excludes these
declarations and their member traversal from the implementation class model.
Their concrete type names remain available when referenced by other declarations.
Implicit uses likewise do not introduce independent interface contracts.
For template-associated class cursors, the extractor distinguishes template <>
specialization headers from explicit instantiation headers using declaration tokens,
ignoring comments. An unrecognized header (for example an unsupported macro
expansion) produces a warning and is not collected; it is never silently classified
as a non-template class or an explicit specialization. Such warnings indicate an
incomplete extracted model and must be investigated before relying on validation.
' One design entity; the interface is checked against each matching specialization.
namespace amp {
class "move_only_function<ReturnType(ArgTypes...), Capacity, Alignment>" as move_only_function {
+ empty() noexcept : bool
}
}
Type Alias Consistency
Every type alias modeled in the unit design entity must exist in the matching
implementation entity. The alias name and normalized original type must match.
(Requirement: Tools.ClassDesignImplementationTypeAliasConsistency)
' PlantUML class diagram
class "Transport" {
using Payload = std::uint8_t
}
// implementation C++ code
class Transport {
public:
using Payload = std::uint8_t;
};
Variable Consistency
Every variable modeled in the unit design entity must exist in the matching
implementation entity. The variable name, normalized data type, visibility, and
static flag must match.
(Requirement: Tools.ClassDesignImplementationVariableConsistency)
' PlantUML class diagram
class "Transport" {
- buffer: std::uint8_t*
{static} - instance_count: uint32_t
}
// implementation C++ code
class Transport {
private:
std::uint8_t* buffer;
static std::uint32_t instance_count;
};
Method Consistency
Every method modeled in the unit design entity must exist in the matching
implementation entity. The method name, visibility, parameters, and method
modifiers must match, and the normalized return type must also match (this
applies to constructors and destructors too, which typically have no return
type on either side). Method modifiers include const, static, virtual,
abstract, override, constructor, destructor, and noexcept. A nonempty
design parameter list constrains a positional prefix: names, normalized types
(see Type Normalization), and variadic/pack-expansion (...) markers must
match. Only trailing implementation parameters may be omitted, without requiring
or inspecting defaults; extra design entries, skipped positions, and reordering
are not allowed. An empty list strictly requires zero implementation parameters.
Top-level const on a parameter is ignored; see
Top-level const on parameters.
(Requirement: Tools.ClassDesignImplementationMethodConsistency)
static, abstract, virtual, and override may each be written either as a
brace qualifier (e.g. {virtual}) or as a stereotype (e.g. <<virtual>>); both
forms are equivalent. override may additionally be written as a bare trailing
keyword after the method signature, mirroring C++ syntax, e.g. + Run() override.
noexcept is only written as a bare trailing keyword, e.g. + Run() noexcept.
An abstract or override method is implicitly virtual (matching C++
semantics), so the effective modifier set includes virtual even if it was not
written explicitly. The visibility classifier (+/-/#/~) is always
written first, before any brace/stereotype modifier, e.g. + {virtual} Run().
Method const qualification may be written as a bare trailing qualifier, e.g.
+ Empty() const : bool, or as a stereotype before or after the return type,
e.g. + Empty() <<const>> : bool or + Empty() : bool <<const>>.
These forms are equivalent and can be combined with noexcept, e.g.
+ Empty() const noexcept : bool. Method qualification is independent of
const in a parameter or return type: + Value() : const int& alone does not
declare a const-qualified method.
The trailing-parameter omission rule applies equally to const-qualified and non-const methods; see the examples under Overload Group Matching.
' PlantUML class diagram
class "Base" {
+ {virtual} Run(): void
+ {virtual} Stop(): void
}
class "Transport" {
+ <<override>> Run(): void
+ Stop() override : void
+ Tick() noexcept : void
}
Base <|-- Transport
// implementation C++ code
class Base {
public:
virtual void Run();
virtual void Stop();
};
class Transport : public Base {
public:
void Run() override;
void Stop() override;
void Tick() noexcept;
};
C-style variadic parameters (e.g. void Log(const char* fmt, ...)) are not
currently supported by the PlantUML parser and are not validated: a design
parameter is always treated as non-variadic.
Method lookup follows Overload Group Matching, including method const
qualification when forming candidates. Thus Check() and Check() const are
distinct overloads, even when their return types are identical. A const mismatch is
rejected in both directions: the design is const-qualified but the implementation
is not, or the implementation is const-qualified but the design is not. For a
unique same-named candidate, this produces a method-modifier mismatch showing
[Const] versus []. With no compatible candidate, one same-name implementation
yields field-level diagnostics (including parameter count errors); otherwise, a
missing-signature diagnostic is reported.
' PlantUML class diagram
class "Transport" {
+ Dispatch(mode: std::uint8_t, payload: vehicle::Payload): bool
}
// implementation C++ code
bool Transport::Dispatch(std::uint8_t mode, vehicle::Payload payload)
Enum Literal Consistency
Every enum literal modeled in the unit design enum must exist in the matching
implementation enum. The full literal data must match.
(Requirement: Tools.ClassDesignImplementationEnumLiteralConsistency)
' PlantUML class diagram
enum "Mode" {
Startup
Shutdown
}
// implementation C++ code
enum Mode {
Startup,
Shutdown,
};
Relationship Consistency
Every relationship modeled on a unit design entity must exist on the matching
implementation entity. Source, target, and relationship type must match.
(Requirement: Tools.ClassDesignImplementationRelationshipConsistency)
' PlantUML class diagram
struct Payload {}
class Vehicle {
+ Load(payload : Payload)
}
Vehicle ..> Payload
// implementation C++ code
struct Payload {};
class Vehicle {
public:
void Load(Payload payload);
};
Free Function Consistency
Every free function (at global or namespace scope) modeled in the unit design
must exist in the implementation. Functions are grouped by fully
namespace-qualified name and follow Method Consistency parameter and
no-candidate diagnostic rules and Overload Group Matching. Return types and
template declarations must also match; class-only visibility/modifiers do not apply.
(Requirement: Tools.ClassDesignImplementationFreeFunctionConsistency)
' PlantUML class diagram
namespace vehicle {
entity VehicleFuncs <<function>> {
+ Dispatch(mode: std::uint8_t): void
}
}
// implementation C++ code
namespace vehicle {
void Dispatch(std::uint8_t mode);
}
Overload Group Matching
For each same-name method group within a matched class, or fully qualified free function group:
Form candidates using positional normalized parameter types, counts, and variadic/pack flags under Method Consistency. For methods,
constqualification must also be equal.Require an injective assignment covering every design declaration: each selects a different implementation; implementation-only overloads may remain unused.
Check parameter names, return types, template declarations, and applicable visibility/remaining modifiers. When parameter-compatible assignments are ambiguous, accept any assignment satisfying all these checks. Multiple valid assignments pass; ambiguity alone is not an error.
There is no exact-first preference, implicit conversion, template deduction, or substitution.
Design declarations |
Implementation overloads |
Result |
|---|---|---|
|
|
Unique trailing omission, no defaults required |
|
|
Pass if either candidate satisfies all field checks |
|
|
Unique group-wide assignment |
|
|
Collision: no injective assignment |
|
|
Pass if any one-to-one assignment satisfies all field checks |
|
|
Unique zero-parameter candidate |
|
|
Parameter-count mismatch, not omission |
|
|
Type mismatch, no conversion |
|
|
Unique trailing omission also applies to const-qualified methods |
|
|
Parameter-count mismatch: an empty design list requires zero implementation parameters |
|
|
Type mismatch: the design must specify a positional prefix, not skip the first parameter |
|
|
Method const-qualification mismatch: non-const and const methods do not match |
|
|
Unique assignment; template declaration matches |
|
|
Unique assignment; trailing template parameter omission is allowed, no defaults required |
|
|
Unique assignment, then template parameter kind mismatch |
|
|
Unique assignment, then template declaration mismatch |
|
|
Pass using the matching template declaration, provided other fields match |
|
|
Parameter type mismatch; no template parameter renaming or substitution |
|
|
Unique trailing omission also applies to non-type parameters |
|
|
Kind mismatch: the design must specify a positional prefix, not skip the first parameter |
|
|
Non-type parameter type mismatch; no conversion |
|
|
Explicit non-type parameter names must match |
|
|
Non-type parameter types match after type normalization |
|
|
Unique trailing omission also applies to template-template parameters |
|
|
Inner template-template lists also allow trailing omission |
|
|
Nested template parameter kind mismatch |
|
|
Template-template and type parameters do not match |
|
|
Type mismatch: declaration-list omission does not omit template actual arguments |
The template<...> f(...) notation above describes declaration metadata, not
template call arguments; return types and parameter names are omitted for brevity.
A unique parameter-compatible assignment can still fail subsequent field checks.
For ambiguous candidates, validation fails only if no assignment satisfies every
field check.
Field-consistency and collision diagnostics include the design and implementation declarations, recorded parameter spellings/flags, and source locations. No-candidate diagnostics follow Method Consistency.
Grouping ignores source location. Methods and free functions normalize spelling
for grouping and merge duplicate records
whose non-location fields are fully equal after normalization.
Distinct conflicting records remain. This is not
full C++ redeclaration resolution. Member const qualification distinguishes
candidates; ref qualification is not represented or checked.
Effect of Partial and Explicit Full Specializations
Class specialization matching and overload matching operate at different levels.
Under Specialization Interface Matching, every implementation partial or
explicit full class specialization with the same fully qualified base name is
checked against the shared design contract. Overload assignment is performed
separately within each matched implementation class, not across a combined
pool of methods from all specializations. Two specializations each providing
f(int) therefore do not, by themselves, create overload ambiguity.
Design contract |
Implementation specializations |
Result |
|---|---|---|
|
Partial specialization |
Unique method assignment in each specialization; both are checked |
|
|
Both pass if each specialization has a field-consistent assignment; ambiguity in |
Design label |
|
Both specializations are checked by base name; missing method in |
In these examples:
Box<T>declares a class template, butf(int)requires anintparameter, notT. Even a design labelBox<int>matches specializations by base nameBox, not by the argumentint.Class specializations skip class template-parameter and specialization-argument checks only; their members and method template declarations are still checked. A matching primary template is also checked if its template parameters match the design (see Template Parameter Consistency).
Methods and free functions follow the overload rules above, with no preference for explicit full function specializations. C++ function templates cannot be partially specialized; additional function templates are overloads.
Type Normalization
Before comparing types, the validator applies limited normalization.
(Requirement: Tools.ClassDesignImplementationTypeNormalization)
Input form |
Normalized form |
|---|---|
|
|
|
|
|
|
|
|
|
|
The last row accounts for a difference between the class diagram and
implementation parser UIDs: dots used as namespace separators are converted to
:: before comparison. This applies to type names, class/entity IDs, and
relationship source/target identifiers alike. cv-qualifiers such as const
and volatile, and the pointer/reference decorators */&, are preserved
(only the spacing around them is normalized). The uint8_t* const row
accounts for the implementation parser printing a const pointer as
uint8_t *const, which is compared against the design form uint8_t* const.
Top-level const on parameters
Top-level const on a by-value parameter is not part of the C++ signature, so
it is ignored when comparing method and free function parameter types. Low-level
const is part of the type and must match.
(Requirement: Tools.ClassDesignImplementationTopLevelConstParameters)
Design parameter type |
Implementation parameter type |
Result |
|---|---|---|
|
|
match |
|
|
match |
|
|
match |
|
|
mismatch |
|
|
mismatch |
Top-level const is not ignored for return types, variable data types, or
type alias original types; those are compared as written. volatile is not
supported by this rule.
The class diagram reader already rewrites :: to . in class/entity IDs,
enclosing namespace IDs, and relationship endpoints of both inputs, so
sequence validators and this validator compare IDs in the same form. Type
names are read as written and normalized only here.
All recorded types require complete normalized equality, including nested
template arguments and qualified owner segments. Declaration-list omission does
not permit omission inside types: Map<K, V> does not match Map<K, V, C>, even
with defaults; bare Map and Map<> are not wildcards. Missing types match only
missing types. No alias expansion, default-argument insertion, or template
substitution is performed; Specialization Interface Matching does not relax
member type checks.
Failure Cases
Failure case |
Validation rule |
|---|---|
Duplicate class ID across unit design class diagrams |
Entity Presence and Type Consistency |
Missing implementation entity |
Entity Presence and Type Consistency |
Entity type mismatch |
Entity Presence and Type Consistency |
Entity template parameter mismatch |
Template Parameter Consistency |
Missing type alias |
Type Alias Consistency |
Type alias original type mismatch |
Type Alias Consistency |
Missing variable |
Variable Consistency |
Variable type, visibility, or static flag mismatch |
Variable Consistency |
Missing method |
Method Consistency |
Method return type, visibility, parameter, or modifier mismatch |
Method Consistency |
Method |
Method Consistency |
Method template parameter mismatch |
Template Parameter Consistency |
No field-consistent member/free-function overload assignment |
Overload Group Matching |
Multiple designs contend for too few compatible implementations |
Overload Group Matching |
Complete normalized type differs, including missing or different template actual arguments |
Type Normalization |
Missing enum literal |
Enum Literal Consistency |
Enum literal data mismatch |
Enum Literal Consistency |
Missing relationship |
Relationship Consistency |
Relationship source, target, or type mismatch |
Relationship Consistency |
Debug Output
The validator emits debug output containing:
the design entity ID being compared
the implementation entity ID being compared
detailed design entity snapshots at trace level
detailed implementation entity snapshots at trace level
type aliases, variables, methods, template parameters, enum literals, and relationships for each matched entity
Failure messages contain source file and source line information when available.
Missing or empty source metadata is rendered as <unknown>.