MDrivenWiki
Log in

Turnkey session 7: Expressions

From MDrivenWiki
Revision as of 12:56, 22 January 2017 by Alexandra (talk | contribs)

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 that 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 more comfortable, we set the main tags mentioned in the video to the right bar menu of this mini player. Choose the interesting subtitle on the list and immediately get to the exact theme timeplace in the video. Now you can pick any topic to be instructed 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

Part 1 OCL Common Expressions Part 2 OCL: Operators Part 3 Derivation properties

We can use the system protoyper to connect to our database and write expressions. There are objects in the database that we need to transport into our application. And this is exactly what the turnkey application does by using different expressions. One common operator is all instances. It takes all of the class referenced and post 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. So we can stack the operators after each other and use all instances to make size returns 4. There are many different operators look at "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 "oreder by" on that property would fetch "A" first "B" then "C" "D" "E" "F". SubSequence operator takes only a subset of returned set from allinstances. For example 1,2, like that, so instead of 4 we have got only two and we could combine, so that's

0:04:26.310,0:04:33.710 add the order by registration number that we had before behind here

0:04:33.180,0:04:39.810 then we get one set and if we would move the order by

0:04:39.810,0:04:43.130 in front the subsequence we get another result

0:04:43.130,0:04:48.860 the most important operator

0:04:48.860,0:04:54.010 that you will use most likely is 'select' it requires some boolean value

0:04:54.010,0:04:57.250 so it checks each and every

0:04:57.250,0:05:00.800 value object that runs through on some property

0:05:00.800,0:05:04.979 checks if it has it and then it either

0:05:04.979,0:05:09.169 chooses to return it or not

0:05:09.169,0:05:12.669 let's now select on tire radius

0:05:19.330,0:05:24.470 in this case a radius bigger than 5 returns 2 objects

0:05:24.470,0:05:26.530 bigger or equal 5

0:05:26.530,0:05:30.470 it returns three objects

0:05:30.470,0:05:35.620 that's okay, when it comes to select you can

0:05:35.620,0:05:38.990 combine any boolean expression like logic operators with 'and'

0:05:42.080,0:05:47.220 and 'or' 'not' and things like that

0:05:47.220,0:05:51.060 so let's add another constraint here to brand.name

0:05:51.060,0:05:56.909 should be Volvo, then we get two

0:06:02.330,0:06:07.319 and one important concept in using select

0:06:07.319,0:06:10.659 is the loop variable

0:06:10.659,0:06:14.009 the loop variable is the name on the

0:06:14.009,0:06:17.139 iterated object it's in the expressions

0:06:17.139,0:06:20.650 gonna call that "one car" then there's a pipe sign

0:06:20.650,0:06:24.710 so means that we could use

0:06:24.710,0:06:27.919 this variable "one car"

0:06:27.919,0:06:31.270 in our expressions it helps when

0:06:31.270,0:06:34.830 the expressions get complex and change

0:06:34.830,0:06:39.190 the volvo brand to audi and see how that works

0:06:39.190,0:06:42.650 okay that was a few things on expressions

0:06:42.650,0:06:45.000 subscribe to this, thank yous