When I set the class as abstract, only its name is displayed in italics. But to be correct from UML point of view, I need the operations to be in italics too. Is this possible?
You have to go into the model explorer and set the "isAbstract" property for the operation you want. See this answer for a walkthrough on how to do it.
Related
I want to describe some models of an API in a diagram. Is there a standard how to mark an attribute as readonly? These attributes are set by the system and cannot be modified by the API consumer.
Currently I abuse the class diagram notation for private and public attributes. But I am not satisfied with this.
Thanks for your thoughts :)
The usual way when you interface coding you would make private properties and use getter/setter operations. You could also leave it on a more abstract level and simply stereotype them with <<readonly>> or <<r/o>>. And finally you could use an appropriate getter method.
Edit The current UML 2.5 spec states on p. 17
Attributes: each specified by its name, type, and multiplicity, and any additional properties such as {readOnly}.
An example on how to use this is found on p. 113:
I am currently building a model from existing C++ code. There is a (dynamically loadable) library that must therefore implement/provide a defined interface (class). The class which is used has some pure virtual functions, but it is - admittedly - not a pure interface (in the Java sense) as it is also a base class containing state (members) and a few method implementations.
So it is kind of a hybrid - base class in C++ reality, but an interface in its main purpose.
Note: I do not intent to generate some code, but the model should be correct for documentation purposes.
When drawing an example in EA (12), some questions arise:
a) are there any important reasons to prefer a class and make it 'abstract' (gray box "Base"), or should I directly use an Interface from the toolbox (purple box "Base2")? So far I could not notice any behavioral difference in EA except the color.
b) How can I suppress the stereotype {abstract} written behind the methods? When I do not set them to "abstract", they are not drawn in italic letters. But I want them italic, without the "{abstract}".
c) Similar question concerning the class/interface boxes: aren't interfaces abstract by definition? So why does EA add the {abstract} text here? It was sufficient to draw the class name italic.
d) I guess that the most left arrow (generalization of a base class) and the most right arrow (realization of an interface) are correct, and the middle one is not. Right?
a) Take either, but be consistent. The difference is a bit esoteric and except for rare cases not worth while (YMMV).
b) It looks like you filled Context/Advanced/Multiplicity with the value abstract
c) Yes. Interfaces are abstract and if you look at the Details tab you'll see that the Abstract box is ticked and can't be changed. I have no idea where that curly bracketed text comes from. It's not a stereotype. The only way I could show it like that was to change the type from int to int {abstract}.
d) You can well implement more than one interface in a class so theoretically all connectors are fine. So Derived implements two interfaces.
Edit As #minastros found out himself (and PMed me) the culprit was one of the zillion flags in the EA options:
As Thomas mentions, an interface is an abstract class technically, although an abstract class isn't always an interface. If you have even one operation (method) that isn't implemented, the class is abstract, so it follows that if none of the operations are implemented, the class is also abstract. An "abstract class" is often only thought of as a class with partial implementation since such an abstract class is different from an interface. However, a class with no implementation--an interface--technically is also an abstract class.
That's probably why EA puts the {abstract} attribute on an interface (it isn't a stereotype in the diagram, it's an attribute--stereotypes use <>). I wouldn't do it myself, since it goes without saying.
Is the following format wrong if I add a pointer to an object of a class, as data attribute of class in Class diagram in UML?
could not find anything about using objects in class diagram, is
underlining the object correct within the class attributes?
I think you may be mis-understanding classes, objects and attributes. Apologies if it's me doing the mis-understanding. So. Here's the short answer:
it's absolutely fine and normal for the type of an attribute to be a Class. In other words, you're not restricted to using primitive types like int, long, char etc.
The consequence is, as you say, that the values of those attributes at run time will themselves be objects. Specifically, instances of the classes Ability, Move and See.
More specifically, each instance of Agent (i.e. each Agent object) will hold references - or more precisely pointers - to 3 other objects: one instance each of Ability, Move and See.
So, assuming that's right, what you have is correct - except for the underlining.
Underlining an attribute or operation says it sits at the class level - not the instance level. It's the equivalent of static in java. Think of declaring constants in class scope, or constructors.
If I understand your model that's not what you want. You want each instance of Agent to hold (a pointer to) its own instances of Ability, Move and See. You don't want all the Agent objects to share the same 3 instances. Assuming so, you don't need the underline.
Hope I understood and that helps.
for a software design project I have to do, I chose the Eclipse Platform as a framework. Meaning I have lots of extension points to implement.
However, I have trouble specifying these extension points in my UML class diagram. So how do I model the fact that a class belongs to an extension point in my class diagram?
Or is the class diagram the wrong place to do this anyway? If so, where is the best place to specify the extension points I implement?
For reference, I am doing the UML modeling with Papyrus. I already have a working prototype of the application, so it is just about creating the diagram.
Cheers
Speaking of Eclipse plugins I would rather choose a component diagram than a class diagram. You can then model extension points as ports and their contract as interfaces (those lollipops).
If you rather have class diagrams specifying extension points as interfaces with a special stereotype (or keyword) would be fine as well.
Regarding the class implementing an extension point you can either use a dependency on the component or (in the second solution) an interface realization.
An eclipse extension point is like an interface: it declares a set of properties that must be implemented.
For example, the org.eclipse.ui.editors extension point declares that to implement this extension point you have to provide:
id
name
icon
class
file extensions
contributors
There is no EXACT way to say this in UML since an extension point is neither an interface nor an object, but you could model it by adding a stereotype to your model, say <<extension_point>> (you can read more about stereotypes here), and create a class in your diagram (for example org.eclipse.ui.editors) that has all of these attributes, with their required types (in this example all attributes are strings, except class which is of type org.eclipse.ui.IEditorPart).
After this you can create another stereotype, say <<extension_point_implementation>> and a new class that has this stereotype. This class you connect with a realization link from the <<extension_point>> class, and then you set the values of all of the attributes to what you are implementing.
Note that this is not "pure" UML since you are defining a new domain with added semantics, but I think that this would be a good and easy to understand way to model what you want.
In a sense extensions are to extension points what instances are to classes; extension points define the possible attributes of the extensions, and each extension contains the concrete attributes conforming to the extension point.
Just reverse the java code and add a note. It would do the job.
how can I add a field, getter and setter to all implementations of MyInterface (in the current project or folder?)
Open the source file containing the
interface. Select the interface's
name and hit F4 (Open type
hierarchy).
In the type hierarchy view, select all of the classes that implement your interface. The hierarchy is displayed in a tree-like fashion so selection should be very easy.
Right-click over your selection, select Source, then Override/Implement Methods....
Mission accomplished.
[Edited]
When I wrote these steps, I thought that your intention was to create stubs of newly-introduced interface methods, in all classes that implement that interface.
Now that I am re-reading your request, I'm having a hard time understanding what it is exactly that you want to do. You wrote:
how can I add a field, getter and setter to all implementations of MyInterface
So, you have an interface named MyInterface and 1,000 classes implementing it.
You would like to introduce a new field, a getter and a setter for that field. So I guess my (and perhaps others') first difficulty is that you can't add a field to an interface, unless it's final - so your wish to "add a field to an interface" just doesn't sound right.
I suppose it would help if you give us a 30,000ft high-level diagram / explanation about your hierarchy and exactly what it is that you're trying to accomplish.
I don't think there's a one-step way to go about this. You could add the getter & setter to the interface, then let the compiler tell you where your implementers are, and it should be a simple copy & paste to place the field, getter, and setter into every class after the first.
Alternatively, you could transform your interface into an abstract class, or introduce an abstract class between your interface and your concrete classes, but that's only if your classes don't already extend other classes.