UML 2.5 Stereotype Application Lacks Mandatory Visibility Constraints
0 reputation · 07 Aug 2025, 11:33 UTC
0 reputation · 07 Aug 2025, 11:33 UTC
The UML 2.5 specification defines stereotypes as reusable profile extensions but does not prescribe a mandatory visibility constraint for the elements they annotate. This omission leaves tool-specific behavior undefined: a stereotype applied to a class marked private may be rendered public in generated diagrams or code if the modeling tool does not honor the element's declared visibility.
Designers must choose between enforcing visibility rules manually through custom validation scripts or relying on tool defaults that may override intended access levels. Commercial tools such as Enterprise Architect and MagicDraw currently allow stereotypes on any diagram element regardless of its visibility attribute, creating a gap between model intent and rendered output.
Verification requires checking each tool's handling of visibility during stereotype application and comparing behavior across versions, since the standard provides no baseline requirement.
UML 2.5 defines stereotypes as a profile mechanism for extending metaclasses, but it does not impose a constraint that forces tools to preserve or enforce the base element's visibility when a stereotype is applied. Visibility (private, package, protected, public) is a property of the named element itself; applying a stereotype adds tagged values and semantics, it does not redefine access rules. So the gap you describe is real: the standard is silent, and behavior is tool-defined. In practice, manual or scripted validation is the accepted practice — there is no vendor obligation to enforce visibility on your behalf.
Confirmed by the specification's structure: UML 2.5's Profiles clause describes how stereotypes extend metaclasses and how they are applied; it does not attach visibility-preservation constraints to stereotype application. Visibility remains an attribute of NamedElement/PackageableElement, orthogonal to profiling.
Likely explanation: The omission is intentional scope separation. Stereotypes are a metadata extension mechanism, not an access-control mechanism. The spec authors left rendering and code-generation semantics to tool vendors and to transformation languages (e.g., MOFM2T/Acceleo, or proprietary generators). The side effect is exactly what you observed: a private class carrying a stereotype may be rendered or generated as public if the tool's transformation ignores the visibility attribute.
Manual validation is the de facto standard. Vendors treat visibility as data the transformation template may or may not consult, not as a rule the tool must enforce. If your models are security-relevant, assume the tool will not protect you and build enforcement into your pipeline.
public for stereotyped elements is the defect to fix.grep -rn "public class" generated/ | grep -f private-elements.txtBecause there is no normative baseline, build a small conformance test yourself:
This reflects UML 2.5 (formal/2015-era specification) and general, long-standing tool behavior; specific vendor defaults in current Enterprise Architect or MagicDraw releases should be verified against your installed version, since vendors do change templates and validation options. One missing detail that would change the recommendation: whether your concern is diagram rendering only or code generation — the fix location (view filter vs. transformation template) differs.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.