Book a Demo

Author Topic: How to add an attribute to an interface  (Read 6056 times)

jdaues

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
How to add an attribute to an interface
« on: July 17, 2009, 11:39:41 pm »
How do I add a method to an interface?

With a class, in the component diagram, I dbl-clk on it, go to the Details tab and click on the Attributes button, but I don't see the same for an Interface.


Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: How to add an attribute to an interface
« Reply #1 on: July 18, 2009, 01:01:27 am »
Sorry, you cannot add attributes to interfaces by definition. As you confused attributes and methods in your posting's title and text, I actually can't guess what you really want to do. If you want to add a method as you wrote, use the operations button.

WBR
Günther

jdaues

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: How to add an attribute to an interface
« Reply #2 on: July 18, 2009, 01:11:08 am »
Sorry for the confusion. In Java, at least, an interface can have members like so:

private double myDouble;
public double getMyDouble();

I want these represented in the UML.


Oliver F.

  • EA User
  • **
  • Posts: 573
  • Karma: +2/-1
  • Aren´t we all in the model business ?
    • View Profile
    • Karl Storz homepage
Re: How to add an attribute to an interface
« Reply #3 on: July 18, 2009, 01:34:26 am »
Quote
I want these represented in the UML.

To the best of my knowledge it is UML that does not define attributes in interfaces.

Even if your attribute was supported in Java (of which I am not convinced) what is it good for? Your method has no body to enforce delivery of the myDouble variable so in fact getMyDouble() can return everything but myDouble in the implementing classes.

So the point of attributes in interfaces is questionable unless you use it as a private static const thus defining a constant.

I would rethink the usage of an interface this way because from my point of view the purpose is questionable.

Oliver

jdaues

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: How to add an attribute to an interface
« Reply #4 on: July 18, 2009, 01:45:06 am »
I gave a poor example. Better would be:

public final double MY_CONSTANT = 1.234;

public double someMethod();

I can define these in the UML by right clicking on the interface box and selecting Attributes or Operations (as suggested by Makulik)

Thanks for your responses.
« Last Edit: July 18, 2009, 01:46:00 am by jdaues »

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: How to add an attribute to an interface
« Reply #5 on: July 20, 2009, 09:38:43 am »
Ctrl+Shift+F9 to add an attribute, or F9 to open the Attributes dialog.

Ctrl+Shift+F10 to add an operation, or F10 to open the Operations dialog.
« Last Edit: July 20, 2009, 09:42:00 am by KP »
The Sparx Team
[email protected]

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How to add an attribute to an interface
« Reply #6 on: July 21, 2009, 08:55:00 am »
Just by way of clarification.  UML does allow attributes on interfaces.  The restriction it enforces is that all attributes and operations have to be public.

The lack of attributes on interfaces is a restriction placed by many programming languages.
« Last Edit: July 21, 2009, 08:55:49 am by simonm »