How to show attribute as "readonly" in UML? - rest

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:

Related

How do we draw abstract method in uml class diagram

public abstract class Shape {
abstract int area();
}
How do we draw the UML class diagram for the abstract method? Use +, - or #?
public class Room {
int nWindows;
}
And what if the class instance variable doesn't have public, private or protected?
Abstract
According to UML specification:
The name of an abstract Classifier is shown in italics, where permitted by the font in use. Alternatively or in addition, an abstract Classifier may be shown using the textual annotation {abstract} after or below its name.
Note however that Operation is not a Classifier. It still has an isAbstract attribute as a BehavioralFeature but 2.5 specification does not define how to model the fact of being abstract. Older specifications (1.4.x) were using the same method as for Classifiers and it is a widely recognized method to show operation abstraction. Note only that the elements in curly brackets for features are presented at the end of line rather than just after the name (Classifier simply has no other specification directly after name).
Possibly authors made an omission in 2.5 specification for Feature abstraction notation by a mistake.
An abstract operation can of course have any visibility kind.
Of course the operation might be abstract only if its containing Classifier (Class in your case) is also abstract.
No visibility kind
In general visibility kind in UML is optional i.e. you can simply omit it. Just take into consideration that UML is a model so it actually can ignore some irrelevant elements or can specify them at a later stage of modelling. Not using any visibility kind in UML does not allow you to make any assumption about it's final visibility kind.
On the other hand if in actual code you use no visibility kind specification (if allowed at all) there is some default behaviour. For example
in Java it's package (#) - in UML understanding, Java calls it "package-private",
in C++ you'll end up with private feature (-),
in PHP such features are treated as public (+)
and so on.

OPAL: Manually creating an annotated method

in the OPAL framework, is it possible to manually create an annotated method?
I currently have the following code:
Method(0, "signaturePolymorphicMethod",
MethodDescriptor(ObjectType("java/lang/Object"), VoidType), Seq())
and I want to add the annotation
#java.lang.invoke.MethodHandle$PolymorphicSignature
to this method. How can I do this?
Annotations are generally stored using the JVM's general "Attributes" mechanism.
In this case the annotation is a non-public inner class of MethodHandle with the "Runtime Retention Policy". Hence, to mark a method as having a "Polymorphic Signature" it is necessary to add the RuntimeVisibibleAnnotations_Attribute to the respective method's attributes table. However, given that the visibility of the annotation is limited to the java.lang.invoke package this is (in this specific case) probably rarely useful. Nevertheless, it is possible to query methods in the respective package

StarUML - cannot indicate abstract operations (italics) in abstract class

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.

MEF: Find type of lazy import

I used InheritedExport attribute, and have a tree of objects. Think IMessageSender where I have SmtpSender, TextSender, HttpPostSender. But through decorator pattern I have additional classes that also inherit this MEF InheritedExport attribute.
However when composing the senders, I do not want to decorators to be composed.
Now Lazy could help, whereas I only retrieve the objects that are not of the Decorator type. But I can't ask Lazy what T actually is. Perhaps metadata could help, but the metadata only applies to the object that has this metadata. I don't want to force implementers (read: developers) to add the correct metadata to their decorator or sender.
Any ideas? Thanks!
I needed to do something similar. In the end I opted to add metadata that gave me the required information, but I can see why that's not ideal for your.
One other possibility would be to switch from using an automatic import via attributes, and explicitly call CompositionService.GetExports instead. Then you'd end up with an IEnumerable of Export objects. This would let you get at the contract name (usually, but not always, the type name) and the contract metadata. I think that the contract metadata always includes the type name, so you'd have the information you're looking for.
You can use the following code, to get the type of a Lazy member:
.GetType().GetProperty("Value").PropertyType

How to model Eclipse extension points in a UML class diagram?

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.