如何在BoUML中规范实现UML规范11.5.5节的限定关联示例11.37?
Great question—this is a common pain point with BoUML's handling of UML qualified associations, especially when your qualifier isn't an association class. Let's break down the proper, UML-compliant way to get the code you need:
1. Correctly Model the Qualified Association in BoUML
First, make sure your UML model aligns with UML 11.5.5's specification for qualified associations:
- Between the
BankandPersonclasses, create or select the existing association. - Right-click the association and choose Add Qualifier, then attach this qualifier to the
Bankend of the association (sinceBankowns the qualified collection ofPersonreferences). - Edit the qualifier's properties:
- Set its Type to
AccountNo—this is the critical step that tells BoUML what type to use as the map's key. - You can optionally give it a name like
accountNoto make the model more readable, but this doesn't affect code generation.
- Set its Type to
2. Adjust the C++ Code Generation Template
BoUML's default template often fails to handle non-association-class qualifiers correctly. Here's how to fix the template for your use case:
- Navigate to
Tools > Code Generation > C++(adjust the path if you're working with another language). - Find the template section responsible for generating Association Attributes (the member variables in the owning class, e.g.,
Bank). - Replace the problematic template line with this corrected version:
${comment}${static}${thread_local}${mutable}${volatile}${const}${stereotype}map<${qualifier_type}, ${type} *> ${name}${value};${qualifier_type}pulls the type of your association's qualifier (exactlyAccountNohere), which provides the map's key type.${type}will still resolve toPerson *as the map's value, which matches your expected output.
3. Validate the Fix
- Save your model and regenerate the code for the
Bankclass—you should now get the correct declaration:class Bank { private: map<AccountNo, Person *> accounts_; }; - For reverse engineering: Importing this corrected code back into BoUML will let it recognize the
map<AccountNo, Person*>as a qualified association (not just a raw map property), since the template aligns the code structure with UML's qualified association semantics.
Why Your Temporary Solution Didn't Work
Using ${association} was incorrect because that template variable is designed to reference association classes—classes attached directly to the association itself, not simple qualifier types like AccountNo. Since AccountNo isn't an association class, this variable couldn't resolve to the right type, leading to both syntax and semantic issues.
内容的提问来源于stack exchange,提问作者zer0hedge

