Turnkey session 7: Expressions

Session 7: In this session, we take a deeper look at OCL expressions and what you can do with them. OCL is a complete language that can act on everything you have in your model. It has operators on objects and on collections. The OCL language is a functional language, different in approach compared to imperative languages like Javascript and c#. The OCL language is optimized for querying your model. It uses a bit of set theory from your math classes. It is compact in the sense that it does a lot with short snippets. OCL is defined by ObjectManagementGroup(OMG).

To make your experience smooth, we set the main tags mentioned in the video to the right bar menu of this mini-player. Choose an interesting subtitle on the list and immediately get to the exact theme navigation item place in the video. Now you can pick any topic to be instructed on without watching the whole video.


"all instances" expression "Last" expression "First" "Order By" SubSequence Combine the expressions Select operator Combine with logic expressions Loop variable

OCL Expressions

To learn more about object constraint language expressions (OCL expressions) you can watch the OCL Sessions Series:

We use the system protoyper to connect to our database and write expressions. There are objects in the database we need to transport into our application. This is what the Turnkey application does by using different expressions.

  • One common operator is allinstances. It takes all the referenced classes and posts them back to the application. Following the explanation in the video, if we have a set of objects, we have different types of operators - likes size, for example, it would return 6, but in our case, we have 4 cars. We can stack the operators after each other and use all instances to make size returns 4.
  • There are many different operators - one of them is "last". It checks the list of retrieved or selected objects and picks the last one. There's an operator called "first" - that does almost the same thing but with the first one.
  • Order by is an operator that could sort our objects on some property. Let's say that is B C A D E F - "order by" on that property would fetch "A" first "B" then "C" "D" "E" "F".
  • SubSequence operator takes only a subset of a returned set from allinstances. For example 1,2, like that - instead of 4, we have only two and we could combine. Following the video, that adds the order by registration number behind the subsequence expression that we have in the debugger.
  • The most important operator you will often use is 'select'. It requires some Boolean value - it checks every value object that runs through on some property. Then, it chooses whether to return it or not. When it comes to "select", you can combine any Boolean expression like logic operators with 'and' and 'or' 'not' or others. One important concept in using "select" is the loop variable - it is the name of the iterated object in the expressions. For example, we are going to call it "one car". There's a pipe sign, which means we could use this variable "one car" in our expressions. It helps when the expressions get complex.
This page was edited 161 days ago on 06/17/2024. What links here