Author Topic: How to Specify Generic Parameter Types?  (Read 3902 times)

Gusztav

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
  • EA expert
    • View Profile
    • Imprestige. Your issues in safe hands.
How to Specify Generic Parameter Types?
« 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:

Code: [Select]
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.)
------------------------
Imprestige. Your issues in safe hands.

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: How to Specify Generic Parameter Types?
« Reply #1 on: June 02, 2013, 03:00:02 am »
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
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

Gusztav

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
  • EA expert
    • View Profile
    • Imprestige. Your issues in safe hands.
Re: How to Specify Generic Parameter Types?
« Reply #2 on: June 02, 2013, 06:00:52 am »
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

Code: [Select]
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.)
------------------------
Imprestige. Your issues in safe hands.

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: How to Specify Generic Parameter Types?
« Reply #3 on: June 02, 2013, 06:40:27 am »
Almost exactly, yes. But the instance name should be:

Code: [Select]
Whatsoeverable<string>
That will keep code generation happy ...
« Last Edit: June 02, 2013, 06:43:17 am by g.makulik »
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

Gusztav

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
  • EA expert
    • View Profile
    • Imprestige. Your issues in safe hands.
Re: How to Specify Generic Parameter Types?
« Reply #4 on: June 02, 2013, 06:11:11 pm »
Thanks :)
------------------------
Imprestige. Your issues in safe hands.