Book a Demo

Author Topic: UML 2 Templates  (Read 5553 times)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
UML 2 Templates
« on: June 20, 2005, 12:51:18 pm »
Searching the forums, a number of postings have discussed C++ Parameterized Classes, notably:
http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?board=suggestions;action=display;num=1050317385;start=4#4
My question relates to UML 2 templates which are an extension on this.

From what I saw in the postings, support for Parameterized Classes is haphazard at best (especially in earlier versions).  In addition, formal support for UML 2 templates (ptc-04-10-02:17.5 Templates) appears almost non-existent. :'(  Somebody correct me if this isn't the case.

So how best to model this in the interim (conceptually) until EA catches up?

Looking at what is available, I decided to create the template using the Parameterized Class functionality.  I propose to create the template by setting the stereotype to «template» and setting the Detail|Templates type to Parameterised and adding the parameters as appropriate.

I will create the bound class by setting the template to «bound» and setting Detail|Templates type to Instantiated.  Rather than use the arguments list, which does not allow formal binding of the bound values to the formal parameters, I thought I would create a new constraint type called "binding"  add the bindings as binding constraints of the form formalParameter -> boundValue and then display the constraints compartment for the class.  This mimics the UML 2 binding syntax.

I would then join the bound class to the template using a Generalization link stereotyped as «bind» (it has been noted elsewhere, that EA doesn't support a binding Realization), so I can get the visual feedback of the (some of ) the effect of binding in the bound class.

The net effect is that the bound class shows up as the inherited features of the template with a constraint compartment at the bottom telling me how to bind the template.

I'm pretty sure I can traverse such structures with automation and I think I can process them satisfactorily with code generation templates.

Thoughts anyone?

Remember, for my needs, I don't have to round-trip.  I just need to be able to emit sufficient metadata to allow a downstream process to generate the code.

Cheerz,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

mattinger

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: UML 2 Templates
« Reply #1 on: June 27, 2005, 08:09:12 am »
I'm struggling with this as well.   I've also noticed that EA (at least 4.5) does not support parameterizing interfaces (which is perfectly legal in java, and in c++ corresponds to a pure virtual template).  I basically have 2 degenerate interfaces, and a third interface which takes 2 type parameters, which are bounded by the 2 degenerate interfaces.  I then have an implementation class which fills these in:

public interface LoadBalancedObject { }

public interface LoadBalancingContext { }

public interface LoadBalancingPolicy<O extends LoadBalancedObject, C extends LoadBalancedContext> {
   O pick(O[] objects, C context);
}

And then the implementation classes:

public class RoundRobinLoadBalancingContext
   implements LoadBalancingContext {
   private LoadBalancedObject previous;
   ...
}

public class RoundRobinLoadBalancingPolicy
   implements LoadBalancingPolicy<LoadBalancedObject,
                              RoundRobinLoadBalancingContext> {
  ...
}

There doesn't seem to be any way to effectively represent this in EA that i can find.