MagicDraw: Template Bindings
Posted by danielmeyer on September 5, 2008
I wanted to create a class diagram for a method returning a Collection<Object> (that is, a Collection of Object arrays).
Why would I need something returning that type of thing? For JUnit parameterized tests.
It wasn’t immediately clear to me how to do this… but here’s how it ended up:
- Create a class. Name it Collection<Object> (which is what it will be in the end if this works!)
- In its Specification, go to Relations:
- Choose Create Outgoing…
- …Template Binding:
- In box that pops up, open the JDK 5.0 Classes folder and navigate to java.util. Find the Collection interfaces. Interestingly enough, we want the Collection one, not the Collection<E> one — Select the “< >” under the plain Collection interface:
…and click OK.
- Back at the class’s Relations page, press the Edit button:
- On the Template Binding dialog that comes up, go to the Template Parameter Substitutions page:
- Then choose press Create, and check the template parameter you want to fill in:
- Fill in the Actual field as Object… but because we want an object array, we also need to choose to show All properties, and then choose  for the Type Modifier field:
…and we’re done.
Or, we could just reverse engineer the code… : )