Enterprise Architect - Inheriting methods from an interface in a class diagram

In Enterprise Architect (version 9.2.921) I want to create a class diagram. I have a class MyInterface

that acts like an interface. So in EA I choose the stereotype <<interface>>

and also marked as abstract


Now, to keep it simple, my abstract interface defines one virtual function. Now I have a class MyChild

which is a child of my interface ( class MyChild :: MyInterface

) and which should implement this functionality.

To do this in EA, I created a new class. Then right click it -> Advanced -> Parent. As the type I select implements

and then select my interface class.

In my class diagram, the correct arrow from child to parent (dashed line with empty arrow towards the interface).

Now the problem is that I expect EA to add my abstract function from the interface directly to the implementation class itself. For example, if I change / add / remove a virtual function in the interface class, it changes immediately in the child classes. But the problem is that the function does not appear in the body of the child class.

Is there a way to make Enterprise Architecht look like this?


source to share

3 answers

First, there is another way to draw connections that you might find easier. If you select a class in the diagram, you will see an arrow icon to the right or right of the class. Click on that, drag it to the interface and release, and EA will present you with a set of possible connectors with the most important ones first. This list is context sensitive based on both the source and target element types (in this case, class and interface).

There are some subtleties when it comes to the Overrides and Implementations dialog.

If a class implements an interface, the class actually has the operations specified by the interface, albeit hidden, even if you don't select them for implementation (which is why interface operations are disabled by default in this dialog).

If you use the class in a sequence diagram and make a call, you will see that you can select the operation defined by the interface in the Message Properties dialog box (if Show Inherited Methods is selected). This name will be updated automatically if you rename the operation in the interface.

If you draw a generalization between the two classes, you get the same behavior in a sequence diagram. Alternatively, you can choose to display the inherited (through generic) operations of a class by right-clicking it, choosing Feature Visibility, and checking Show Operations. Note that this only works for operations derived from generics (from other classes), not from implementations (from interfaces). I consider this to be a bug, but it might be by design.

If you select an operation in the Overrides and Implementations dialog box, you are making a copy of it. EA has no memory of where the overridden operation came from and will not update the name if you change it in the interface / abstract class.

Using the Right-Click Method - Advanced - The parent method bypasses the Overrides and Implements dialog box, but creates a connector as you noted.

Now you indicate that you are creating a class and then set the "interface" stereotype. This is not the way to do it; instead, you must create an interface using the interface symbol in the toolbar. A class stereotyped as "interface" is not the same as an interface, and I'm not sure which of the behaviors I described you get with this construct.

If you want an interface, use it. If, on the other hand, you are talking about an abstract class, then the class is correct, and neither the abstract nor the concrete class should have an "interface" stereotype.

Note also that if you have a code base that you want to draw diagrams on, perhaps EA can redesign it for you (if it's in C ++, C #, Java, or about a dozen other languages).



Ok I found a way:

  • Remove connection between two classes (if there was one already)
  • Select Realization

    from Class Relationships

    in the toolbar
  • Draw a line from your Child class in the frontend
  • When you release the mouse, you will be prompted to select the function your child should implement

This way you don't have to reintroduce all function prototypes over and over, but if you change the prototype in the interface, it won't change the corresponding function in the implementations. (There may be another way, but I don't know it yet ...)



I had the same problem.

I am not very happy with the answer. How to "remove" an implementation

  • If "Delete" = "Hide in Diagram", you will have two Implementation Wizards at the end
  • If "Remove" = "Remove from model", this Assoc will be removed in other diagrams where it was used


All Articles