In Enterprise Architect ( Version 9.2.921 ) I want to make a class diagram. I have a class MyInterface
which acts as an Interface . So in EA I choose stereotype <<interface>>
and also marked it 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 shall implement this function.
To do so in EA, I created a new class. Then right-click on it --> Advanced --> Parent .
As type I pick implements
and then I choose my Interface class.
On my class diagram the arrow from child to parent is correct ( dashed line, with empty arrow head in direction of the interface ).
Now the problem is, I would expect EA to add my abstract function from the interface right into the implementation class itself. So for example if I change/add/delete a virtual function in the Interface class it gets right away changed in the child classes. But the problem is, the function doesn't show up in the body of the child class.
Is there any way to do make Enterprise Architecht do this?
First off, there's another way of drawing connections which you may find easier. If you select the class in the diagram, you'll see a little arrow icon appear just above/right of the class. Click this, drag to the interface and drop, and EA will provide you with a set of possible connectors, with the most relevant ones first. This list is context-sensitive based on both the source and target element types (in this case, class and interface).
When it comes to the "Overrides & Implementations" dialog, there are some subtleties involved.
If a class realizes an interface, the class actually has the operations specified by the interface, although hidden, even if you don't select them to be implemented (which is why the interface operations are deselected by default in this dialog).
If you use the class in a sequence diagram, and make a call to it, you will see that you can select the interface-defined operation in the "Message Properties" dialog (provided "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 two classes, you get the same behaviour in the sequence diagram. In addition, you can select display of a class' inherited (through generalization) operations by right-clicking it, selecting "Feature Visibility" and ticking "Show Operations." Note that this only works for operations arrived at through generalizations (from other classes), not realizations (from interfaces). I consider this a bug, but it may be by design.
If you do select an operation in the "Overrides & Implementations" dialog, that means you are making a copy of it. EA will not remember where the overridden operation came from, and won't update the name if you change it in the interface / abstract class.
Using the right-click - Advanced - Parent method bypasses the "Overrides & Implementations" dialog but creates the connector, as you've noted.
Now you mention that you create a class and then set the "interface" stereotype. This isn't the way to do it; you should instead create the interface using the interface symbol in the toolbox. A Class with the "interface" stereotype is not the same as an Interface and I'm not sure which of the behaviours I've described you'll get with that construct.
If it's an Interface you want, use that. If on the other hand you're talking about an abstract class, then Class is right and neither the abstract nor the concrete class should have the "interface" stereotype.
Note also that if you've got a code base you want to draw diagrams for, chances are that EA can reverse-engineer it for you (if it's in C++, C#, Java, or about a dozen other languages).