OCUP UML operation semantics example - uml

I am currently learning for the OCUP UML Fundamental exam.
While reading the book i found something strange about operations.
The semantics of an operation:
[visibility] name (parameter list)[:type][{property strings}]
now there are the following examples:
- getPoistion(return x: int, return y: int)
- enlarge(byFactor: Real) : GeomFigure
- +addPhone(phone:String)
- deposit(in amount, Amount): Amount
- #release(): contractStatus
- "create"create()
The last one i think is odd. Can someone explain me why this is allowed?
Since the only semantics that is allowed before the name is a visibility modifier.
Kind regards,
Wim

The chapter 2.2.11 OPERATIONS, page 49, in the book http://issuu.com/maurosergio/docs/uml_2_certification_guide_-_fundamental_and_interm that you are quoting also says
..Notation and Semantics..The syntax for operations..the notation should look like this..
The notation does not define/restrict semantic meaning of operations. It specifies general useful syntax.
The "create" message has in UML special behavioral meaning (don't know where is it explained in the book you are reading). For example look here http://www.uml-diagrams.org/sequence-diagrams.html, see <<create>> stereotype in the diagram and create message later in the text.
Also see "Object Creation Message" chapter here http://www.uml-diagrams.org/uml-object-oriented-concepts.html#message
Kirill Fakhroutdinov's online book www.uml-diagrams.org is very good UML reference compiled by the author from official sources (UML specs) and also from other background non-UML sources and from some "common sense".
Browsing through this book might be easier way to prepare for the exam, or at least consider it as alternative reading. Many "visual" examples included
and welcome to Stack Overflow and also read https://stackoverflow.com/help/someone-answers

Where exactly have you found this example? It really looks like incorrect and definitely does not comply to the formal expression stated above.
These are the examples frm the last version of UML spec and all are perfectly fine:
9.6.5 Examples Normal Operations:
display ()
-hide ()
+createWindow (location: Coordinates, container: Container [0..1]): Window
+toString (): String
A template Operation: f <T:Class>(x : T)
A binding of that template Operation. f << T -> Window >>(x : Window)
NOTE. Parameters may be suppressed; .
If you have taken the example from an informal source, it is clearly an error. I would forget about it. :)

Related

How to navigate through association class to create constraints with OCL?

I'm struggling to find a way to navigate through association class to create constraints
I checked on the specification here: https://www.omg.org/spec/OCL/About-OCL/
It's says:
Let say I have this class diagram:
And this object diagram:
As you can see I created a constraint in the context of class A (just below the name of the class), I tried with lower "c" and upper "C", neither work...
Context A:
inv: self.C[b].val.mod(2) = 0
(The meaning of the constraint is not important, i just would like to make it work)
When I execute the validation process I get this error:
"Expression has errors: Semantic errors at [0:5]: Unrecognized variable: (C)"
This error message seems to be logic as I don't see an attribute "c" or "C" either in the object of type A, but I don't understand why it's that so.
Am I doing something wrong ?
I don't understand why it doesn't work as I respected the syntax described in the specification.
For information:
I use:
magic draw: v18.5
OCL: 2.0
Thank you by advance !
You looking at a very dark corner. My first attempts at actually testing this functionality foundered on a failure to find a UML tool that could actually draw Fig 7.1. Once I got to grips with the text I realized there are many problems; a potential conflict between two different x[y] syntaxes, further aggravated by a QVTo shortform. There is a problem with extension to more than binary associations. The OCL Abstract Syntax continues to use the UML 1.x concepts of AssociationEnd rather than the UML 2.x Property.
Consequently the functionality you observe is the result of the best endeavours of some tool vendor to make sense of a very inadequate specification.
With MagicDraw, you used to be using Dresden OCL, but I understand that MagicDraw has switched to Eclipse OCL, perhaps the Classic Eclipse OCL. NoMagic seem remarkably reticent in crediting the open source software they redistribute.
For the newer Pivot Eclipse OCL where I prototype solutions to many of the OMG OCL problems, the UML to Pivot loading normalises many of the UML concepts so that Associations are redundant, unless an exoplicit navigation to the Association requires an Association Class to be reified. AssociationClasses are normalized to Association Classes with ordinary Properties for each plausible navigation.
I think that your expression is incorrect.
self.C[b] cannot be a qualified association since the implicit A::C property has no key.
self.C[b] could be a disambiguated navigation A::C where the ambiguity of A::C is resolved by selecting the C::b opposite. But A::C is not ambiguous and its opposite is C::a. So self.C should be adequate, self.C[a] is redundant, self.C[b] is wrong wrt the b. Sadly your tooling dislikes self.C so your tooling is defective.
I think you should have written self.C.val.mod(2) = 0.
Uppercase C is correct. Lowercase was misguidedly suggested by OCL <= 2.2 following the UML style guide. See indented paragraph under "Missing Association End names" in 7.5.4 of OCL 2.4.

In UML class diagrams, is there specific differences between operations and constructors?

I'm taking a Data Analysis course, we're covering UML class diagrams. I keep getting confused by the terminology of methods (operations) and constructors. What is the difference between a method and a constructor? Any explanation would be greatly appreciated, the light bulb for this just hasn't lit yet and hope some outside perspectives will help. Thank you in advance!
Some of the confusion has historical reasons where terms were defined only partially (or not at all). The current UML spec 2.5 defines on p. 114
9.6.3.1 Operations
An Operation is a BehaviorialFeature of an Interface, DataType, or Class. An Operation may be directly invoked on instances of its featuringClassifiers. The Operation specifies the name, type, Parameters, and Constraints for such invocations.
Sounds a bit like blurb, but basically this is what a programmer would call a function.
Method in contrast (which formerly has been used alternatively to Operation) is defined on p. 13
For example, an operation owned by a class may have a related method that defines its detailed behavior.
So the method is the "how to" of an operation and can be described by various means like e.g. a StateMachine and more.
Finally a Constructor is a certain operation which by is executed during initialization of an object. On p. 15:
Therefore, when modeling the detailed behavior of the instantiation of a classifier, it is a modeler responsibility to ensure that the modeled behavior carries out the proper initialization of any attributes with default values once the object is created. (This is often done by encapsulating the instantiation behavior for a class in a constructor operation – see sub clause 11.4 – in which case the initialization of the attributes becomes an implicit postcondition for the constructor.)

Meaning of exclamation/question mark before UML method name

My teacher uses exclamation marks and question marks before method names in UML class diagrams to distinguish between commands (!) and queries (?):
As I've never seen this before, I wonder whether it's actually used in practice or not and what the actual meaning is.
Basically, commands are methods that don't have a return type whereas queries are methods that do have, so I consider these symbols to be redundant. Moreover I couldn't find anything about this notation on the internet.
I'd really appreciate a clarification.
This is no official notation. Besides the fact that prefixing things which are obvious through their signature is pointless, it will just confuse readers which are not familiar with that kind of notation.
As remarked by Anna Vopureta and Thomas Kilian, the notation used by your teacher is not standard UML. But as pointed out in the article of Martin Fowler recommended by Anna Vopureta, and missing in the asnwer of Thomas Kilian, it makes sense to distinguish between those operations/methods with return value that represent pure queries (not changing the state) and those that do not (due to state changes).
So, we have to deal with three cases:
operations/methods without return value
operations/methods with return value
changing the state
not changing the state (pure queries)
A pure query method can be expressed in a UML class diagram by appending the operation property query in curly braces to the operation declaration.
In your example the correct operation declarations would be
+foo()
+bar1(): int
+bar2(): int {query}

Using variables in UML multiplicities

I was running a tutorial today, and a we were designing a Class diagram to model a road system. One of the constraints of the system is that any one segment of road has a maximum capacity; once reached, no new vehicles can enter the segment.
When drawing the class diagram, can I use capacity as one of the multiplicities? This way, instead of having 0..* vehicles on a road segment, I can have 0..capacity vehicles.
I had a look at ISO 1905-1 for inspiration, and I thought that what I want is similar to what they've called a 'multiplicity element'. In the standard, it states:
If the Multiplicity is associated with an element whose notation is a text string (such as an attribute, etc.), the multiplicity string will be placed within square brackets ([]) as part of that text string. Figure 9.33 shows two multiplicity strings as part of attribute specifications within a class symbol. -- section 9.12
However, in the examples it gives, they don't seem to employ this feature in the way I expected - they annotate association links rather than replace the multiplicities.
I would rather get a definitive answer for the students in question, rather than make a guess based on the standard, so I ask here: has anyone else faced this issue? How did you overcome it?
According to the UML specification you can use a ValueSpecification for lower and upper bounds of a multiplicity element. And a ValueSpecification can be an expression. So in theory it must be possible although the correct expression will be more complex. Indeed it mixes design and instance level.
In such a case it is more usual to use a constraint like this:
UML multiplicity constraint http://app.genmymodel.com/engine/xaelis/roads.jpg

Alloy 4, Software Abstractions 2E, and the seq keyword

Not long ago I acquired the second edition of Software Abstractions, and when I needed to refresh my memory on how to spell the name of the elems function I thought "Oh, good, I can check the new edition instead of trying to read my illegible handwritten notes in the end-papers of the first edition."
But I can't find "seq" or "elems" or the names of any of the other helper functions in the index, nor do I see any mention of the seq keyword in the language reference in Appendix B.
One or more of the following seems likely to be the case; which?
I am missing something. (What? where?)
The seq keyword is not covered in Appendix B because it's not strictly speaking a keyword in the way that set and the other unary operators are. (Please expound!)
The support for sequences was added to Alloy 4 after the second edition went to press, and so the book needs to be augmented by reference to the discussion of new features in Alloy 4 in the Quick Guide and the Alloy 4 grammar on the Web site. (Ah, OK. Pages are slow, bits are fast.)
Other ...
I guess, to try to put a generally useful question here, that I'm asking: what exactly is the relation between the language implemented by the Alloy Analyzer 4.2 (or any 4.*) and the language defined in Software abstractions second edition?
The current implementation corresponds to this online documentation.
Sequences are really not part of the language; x: seq A can be seen just as a syntactic sugar for x: Int -> A, and all the utility functions (e.g., first, last, elems) are library-defined (in util/sequence). The actual implementation is a little more complicated (just so that we can let the user write something like x.elems and make the type checker happy at the same time), but conceptually that's what's going on.

Resources