Part 2 OCL: Operators
No edit summary
mNo edit summary
Line 97: Line 97:
</script>
</script>
</html>
</html>
'''Raw subtitles text'''
I welcome back this is session two of
the ocl expressions extending the model
with a fruit bowl, given it a property
name and then this is also new that you
when you enter code comments on
classes, you will have access to them
in the ocl editor, so this will help you
as your model grows to know what is what
so in the ocl editor, whenever you edit something and you point at it
it says the code comments, so that's a new thing
ok and the fruit bowl, it's supposed to contain fruit
toggle square line to ensure that
Association line is always squared
going to give the association ends better names
than the defaults and this is the multiplicity and
it's 0 to many and in the other end
it's 0 to 1, so the fruit can be in one bowl and bowl
can contain many fruits, that's either in orange or an apple
so re-reading the model
create a bowl and this is a way to, in ocl,
to introduce temporary variables
let's make it easier for you to set
multiple properties just showing you for
this is the purpose of this video so
let the let operator temp is a temporary variable from both create in
and then you can use the temporiable
you can set the property, so this is one
expression that creates and sets the
property in one goal
going to create another one plastic bowl
one glass bowl and one plastic bowl
there we have them, first I'm going to work on the glass
bowl, it's a collection of fruit bowl, but I
just one to one, so I say first.FruitinBowl
that's the collection of fruit I want to
add fruit, add operator
so now I need to find a fruit
fruit.all instances, but that's a collection of fruit
I need one fruit to add I used to at(0)
operator again, grabing a zero fruit
the first fruit and then I change
this to add another fruit
and then I would be able to see rather
in the glass bowl the fruit in bold
I see I have three fruits, two oranges and
one apple, ok and let's add an attribute that states
what it contains, contains this fruit to
make that derived and the derivation
should be fruit in bowl presentation but
that will be a collection of string, we
need a single string and there's an
operator asCommaList simply takes a list
of strings and sets a comma between each
re-read the model like that "contains this fruit"
that's the glass bowl, but ocl also has an "if" operator, so
let's see if the fruit in bowl is empty
then we return the string "no fruit at all"
else wereturn the one we just constructed
and if ,it's important to end your
expression, and both parts of the
expression must return the same type in
this case a string, so if we look at all
the fruit bowls, we can spell all
instances correct,  we see that the glass bowl
has fruits and the plastic bowl has
no fruit at all, but if I were to add
fruit to the glass bowl, the derived
property would get another apple in this
case undo that, we do under so fully
subscribe and what if we were to add one to the plastic bowl
now we'll see a important principle that
our model states that the fruit can only
be in one bowl at a time, so
adding it to get up on the bowl to the
plastic bowl, actually removes it from
the glass bowl, this is of course obvious
but not so obvious when programming
against databases etc
modeling really helps us to work in high level of
abstraction to do things right
just to say supposed to be straightaway
avoiding a lot of simple mistakes w
we have a groupby operator in ocl, that we
can use to certain things
let's see how it works, if you have a
collection of something you can collect
over it and state what you want to group
by what's the unique property that you
want to isolate and keep and sort,
to group the other items by, so I want to
order by the type, ocl typename, but wait
a minute this wasn't what I expected
it's a string, I wrote the wrong thing I
wrote the property contains this fruit
when I intended to write the association fruit in bowl
so now I have first, part one that will
contain the type name and then a list a
list of the ones that are of the type, so
then we can continue and use to result
can collect and get the presentation of each fruit in the list,
yeah since the list contains many it
will be a collection of
no, actually, that the list needs to have...
it needs to, its case sensitive
the property was named list with the big L
you need to get that, like this,
asCommaList to reduce the collection of
strings, to a simple string, ok so
and now we have grouped the fruits in
the bowl and oranges on one end and a
apples on the other end and when we
remove or move the fruit we will see the effect
and let's copy that and do and yet
another tuple part, summing up the weights
there is an ocl operator sum
that just adds up all the numbers and
let's elaborate a bit on what to write
so the orange weight sums up to 43 grams
the apple weight sums up to 21 grams
but the groupby only chcks on type
name, what we can do is also add another
criteria to the grouping and that would
be what bowl the fruit is in
like that, so now we know what bowl
the fruit is in and we could use that
information in our text presentation
the tool tuple +x and there's a new part
of the tuple, but wait a minute
it's not called part2 since this is a
strict model name InBowl, we can use that
when we create a tuple, so that's
used, so this expression it's rather harry
but then if we remove the criteria
to only check the glass bowl we will see
that the use of it, now we sum up and see
that the plastic bowl has the weight of 23 grams
let's set another derived
attribute on the fruit bowl
summing up the the weight of the
contents, derived, derivation ocl
should grab the fruit in the
bowl, the weight and the operator sum
so re-reading the model
we see the weight of the contents and we
see contains this fruit, etc
if we add a move fruit the things update
in there debugger you can add your own
variables to make it easier for you to do things
let's add a variable for the glass bowl
and another one for the plastic bowl
so this is the name of the variable, colon,
the type of the variable, then action you can
there are three collections
m1 m2 and m3 that you can easily assign to
from the selected things in the
result list, so this will give you a good
way to access specific objects, so let's
see if I manage to assign the glass bowl
to m1 and then the plastic bowl to m2,
which I selected, like that
these are actually collections of one
no, there are objects, sorry
so the glass bowl is of type "fruit
bowl" so it has property contains this fruit
and you can follow the associations, ocl
editor is acting up them I'm taking
I'm taking notes to fix these after I've done this presentation
so what I really want to do now is to show you some of the
operators that work on collections
so we have the union of
course, we saw that before and
we also have an operator called intersection
that use fo from time-to-time
intersection is, well it's the intersection between
two collections, so what equals the two collections
what thing is in both, so if I do the
glass bowl and a collection with orange all instances
I will get all oranges in the glass bowl, fruit all instances will
of course return all the contents of the
glass bow,l because there's nothing else than fruit in it
another operator symmetric difference
the sets contain and contain all the elements that are
in set two, and set one and set two, but not in both
so this will be the all the fruits that aren't assigned any fruit bowl all the apples
so and I want you to get to know these
operators as they will help you to
express yourself and to get the business
rules, that you're after in an efficient manner
yet another operator is the difference
it's like the symmetric difference but
it's trickier, because it's not symmetric
so you need to take care of what
collection you put aware, so if you flip this around
you will get another very different result the collection one and
the collection two that is, so again just try them out
it's easy to to do in the debugger and
then I will close this session and get
right back with the third part

Revision as of 20:35, 15 April 2017

An introduction to OCL - the object constraints language - by example. The session also introduce the new MDriven debugger and shows how to get instant results of modelling efforts. This particular session explains the configuration of different operator, concept of derivation and principles of various ocl associaton tools by practical example . It's as closely clear and understanble to learn and to be taught with.

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.


This part includes overview on:
    code comments associations temporary variables introduction (temp operator) add operator at(0) operator derivation asCommaList operator if operator groupby operator sum operator add criteria to the grouping adding a variables m1, m2, m3 collections Collection operators
      symmetric difference operator difference operator

This page was edited 99 days ago on 02/10/2024. What links here