Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: Gusztav on June 02, 2013, 01:30:28 am
-
Hi,
Say I have a generic interface interface Whatsoeverable<T> and I have a class Foo. Say, moreover, I want to define a method named DoSomething woth a parameter withThing of the Whatsoeverable<string> type, something like this:
public interface Whatsoeverable<T> { ... }
class Foo {
public void DoSomething(Whatsoeverable<string> withThing) { ... }
...
}
Now the question is how can I specify the templated type for the parameter in EA? In the type selector, I can only select the interface, but there seems no way to formally define the parameter substitution T = string other than typing by hand which is not what I want, since in this case the loose reference may not be realized by EA (that is, it may not know that I'm actually using that interface).
(I know I could create an intermediary class Superfluous of the type Whatsoeverable<string>, and than use it as the type of withThing but it would unnecessarily increase the model's complexity.)
-
Usually it's done using a <<bind>> relationship (it's a dependency stereotype) for the definition of a template instance. You have to do it for every instantiation used (yes, this increases the complexity of the model).
HTH
Günther
-
Hi Günter,
Thanks for the response. Do I understand correctly you mean there is no way for this as I wanted and I need to create a class like this
class WhatsoeverableString: Whatsoeverable<string> {}
and then set WhatsoeverableString as the type of the parameter? (It is clear that in UML notation, WhatsoeverableString will have a <<bind>> realization to Whatsoeverable<T> with T = string in this scenario.)
-
Almost exactly, yes. But the instance name should be:
Whatsoeverable<string>
That will keep code generation happy ...
-
Thanks :)