Questions tagged [ocl]

A formal specification language used with MOF meta-models (including UML) to express queries or constraints that cannot otherwise be expressed in diagramic notation.

The object constraint language (OCL) can be used to define invariants, queries, pre- and postconditions for MOF meta-models (including UML models). It allows a user to specify constraints on models, which can not be specified by the graphical notation of the UML.

OCL itself is a side-effect free, typed language based on first-order logic.

Invariants are defined for a context, typically a class. The following invariant states, that all person names should be unique:

context Person inv namesUnique:
  Person.allInstances->forAll(p|self.name=p2.name implies self=p2)

Note, that OCL provides the built in operation allInstances() to access all instances of a class.

Pre- and postconditions are specified in the context of an operation. In a post condition the special operator @pre can be used to access the values of variables, ettributes, etc. before an operation was called. Also, the special variable result can be used to access the result of the operation call.

The following conditions could be specified for an operation pop():OclAny of a Stack:

pop():OclAny
  pre  self.size > 0
  post self.size = self.size@pre - 1
  post result = self.elements@pre->last()

Beside constraint definition, OCL is used as a query language in model transformation approaches like QVT.

Further information about OCL can be found on the websites of the OCL workshop or the OCL Portal.

180 questions
3
votes
2 answers

Is there a way to check the validity of a model in a programmatic manner such as Validation > Validate Model does?

Is there a way to check the validity of a model in a programmatic manner such as Validation > Validate Model does?
KMex
  • 71
  • 3
3
votes
3 answers

Translating ecore models (accompanying OCL expressions) to alloy specification

I am looking to see if there is any tool or engine which translates Ecore (meta-)models to Alloy specification? if it does this translation considering accompanying OCL expressions, it would be great :) Thx
qartal
  • 2,024
  • 19
  • 31
3
votes
1 answer

OCL constraints checking on Eclipse Papyrus

Does anyone manage to check OCL constraints on a class diagram modeled in Eclipse Papyrus ? I have definied a simple test profile with only one constraint on a stereotype attribute : {OCL} self.property > 0 The stereotype extends the Property…
Vincent
  • 666
  • 7
  • 21
3
votes
2 answers

Groovy equivalent to OCL forAll

What is the Groovy equivalent to the forAll method in OCL? Let's say that I have a list of items. def items = new LinkedList(); What is the Groovy way to express a predicate that holds if and only if all items match a certain criteria? The…
Dušan Rychnovský
  • 11,699
  • 8
  • 41
  • 65
2
votes
4 answers

OCL - Need some clarification on Invariants?

I had a discussion with a professor today on OCL. He believes invariants, post-conditions, and pre-conditions are allowed within the defined contexts of functions. The software developer in me leads me to want to believe OCL would allow general…
Joshua Enfield
  • 17,642
  • 10
  • 51
  • 98
2
votes
1 answer

OCL - Composition relation, can it be referenced backwards?

So suppose that I have a simple relation where a "Car" is composed of "Wheel" (Through "has" relation). I know that in the context of Car, I can navigate, in OCL, easily to see the wheel associated with this car, by writing self.has to obtain a set…
Yan Zhuang
  • 436
  • 3
  • 10
2
votes
1 answer

Can you use dot notation when referring to classes in relation to other classes in OCL?

For example, let's say I have a situation like this Can I write an OCL expression that counts how many students a school has, such as: School.students->count() ? Or would it be incorrect? And in that case, how would I count the number of students?
tofana
  • 83
  • 1
  • 5
2
votes
1 answer

Is there an alternative to OCLE 2.0?

In this "CASE Instruments" course the teacher said this software "OCLE 2.0" is the only software that can validate and compile UML. Is there an alternative?
sweethuman
  • 134
  • 7
2
votes
1 answer

Equivalence of if-then and implies in OCL statements

Are the following two OCL statements equivalent for some function context? post: if a > 0 then b < c post: b < c implies a > 0
a_fan
  • 383
  • 2
  • 22
2
votes
2 answers

Parse an OCL Expression into an AST (Abstract Syntax Tree)

for context - the OCL Expressions will be given alongside an "Ecore" file that holds information regarding the UML that the expression is associated with. As a part of a research I'm conducting I'm trying to parse an OCL Expression into an Abstract…
Amit Wolf
  • 23
  • 4
2
votes
2 answers

UML/SysML: OCL specification of a derived property counting the number of a specific relation/stereotype

I'm currently working on a UML/SysML profile (using the Cameo Systems Modeler (NoMagic)). I created two new stereotypes. One is a new relationship with the metaclass dependency «collaborates» and the other is a class stereotype called…
Jannecee
  • 21
  • 1
2
votes
1 answer

Difference between UML and OCL

I have been asked make and present an application design using UML. However, while doing my research, I have run into OCL. They seem to be almost the same. That is, they both do classes and their attributes and the relationship between the…
Mamun
  • 2,322
  • 4
  • 27
  • 41
2
votes
3 answers

How to specify the unique identifier of a Class

I have to indicate for the Employee class that each employee can be clearly identified by his personal number. I do not know if I think too complicated, because I have no real idea. Attributes: final int personelNumber ...
M. Schwarze
  • 59
  • 1
  • 5
2
votes
3 answers

Model as Backend

first of all: I'm new to the EMF world. I worked through the Book "Model driven software engineering in practice" and now I want to apply this in a project: I "meta modelled" my Project and implemented some OCL Constraints, which is therefore like…
Laureeens
  • 23
  • 5
2
votes
1 answer

Defaultstringrepresentation in MDriven not showing

Working on a timetracking database in MDriven. Trying to implement the different integers in a nicer way with strings but had some issues in "the New Debugger" I have an instance with "Employee" having the attribute "Age" and would like it to be…
Gustaf
  • 147
  • 5
1
2
3
11 12