UML 2.5.1 Visibility: Protected Modifier Mapping Across Architectural Layers
0 reputation · 12 Mar 2024, 05:55 UTC
0 reputation · 12 Mar 2024, 05:55 UTC
In UML 2.5.1, visibility modifiers such as Public (+), Private (-), and Package (~) are used to define encapsulation boundaries for attributes and operations within a classifier. While these notations map clearly to most object-oriented languages within a single module, ambiguity arises when modeling transitions between distinct architectural layers.
The goal is to maintain strict encapsulation when bridging a domain model to a Data Transfer Object (DTO) layer. There is uncertainty regarding how the Protected (#) modifier should be interpreted when a subclass exists in a different architectural layer or package than its parent, specifically concerning whether the visibility remains restricted to the inheritance hierarchy or expands based on the layer's boundary.
35275 reputation · 12 Mar 2024, 11:16 UTC
In UML 2.5.1 a # (protected) visibility is defined as “visible to the owning classifier and its descendants via generalization.” The UML language has no notion of architectural layers, modules or deployment boundaries, so it cannot limit protected visibility to a single package or layer. In other words, the specification provides no formal mechanism to restrict protected visibility across separate architectural layers.
~ makes it visible only to elements that belong to the same package.# maps differently: Java protected is package‑plus‑subclass, C# protected is subclass‑only, C++ protected is subclass‑only, and Python relies on convention.<<layerProtected>> that enforces layer boundaries via tool‑specific validation rules.NamedElement and apply to its owning Classifier and any Generalization relationships.~) is the only kind that respects namespace membership; protected ignores package boundaries for subclasses.Domain and DTO.Domain::Entity with a protected attribute #id.DTO::EntityDto from Domain::Entity and generate code for Java and C#.EntityDto can access id (because protected includes same package), whereas in C# it cannot (protected is subclass‑only).id in a public API, change the visibility to ~ or move the class into the same package.Which implementation language are you targeting? The mapping of protected visibility differs between Java, C#, C++, and other languages, and that may influence the exact strategy you need to adopt.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.