Tricia Balfe explains us today how to get more out of our OCL rules with Nomos (another reason to learn OCL). Enjoy!
Enter Tricia:
OCL is great for modellers who want to ensure models are correct. But it’s also really valuable as a way to model more. Plenty of organisations build data models. Using OCL, you can add business rules to the data models. The models are more complete, and the OCL can be used to generate executable rulesets for use in downstream systems: either test or production.
This streamlines the process of managing rules in a system. The modellers and analysts, who understand the domain, can define the rules completely in the model, execute and test them, and then deploy. It’s real division of labour resulting in real efficiencies. No more handing over ambiguous textual descriptions of rules to programming teams, with all the duplication of effort that that entails.
Here’s an example of a very simple MagicDraw model that includes OCL rules. It models a file containing bank ‘payment’ requests or payments records
And to see the rules in the MagicDraw environment in a little more detail:
At Nomos, we build products that generate executable java rulesets from OCL. The products currently support execution of OCL invariants and OCL queries over XML data – where the XML conforms to an XML schema, and the XML schema is a model transformation as in the diagram below.
The rulesets can be deployed as java archives, or can be deployed behind the Nomos Validation Web Service. By building a simple Web Service client, the rulesets can be called from any platform. The client passes an XML file to the web service, identifying the ruleset(s) against which the XML file needs to be validated, and is returned a list of errors.
The Nomos RuleX product provides the capability of building and executing these OCL-based rulesets. For MagicDraw users who want to build rulesets directly from MagicDraw, we provide the Cameo OCL Transformer, and for IBM RSA users, we provide the OCL Transformer for IBM RSA.
Here’s an online test service for payments messaging that built with OCL business rules. The test service is used by banks and corporates around Europe to test payments messaging. The messages are modelled in UML and XML schema, and the service is built using OCL business rules that describe the validation checks that the XML payments must comply with.
So OCL isn’t just useful to make sure models are correct. Models can be extended to include OCL business rules: the models are more complete, and you can generate executable rulesets from them. The rulesets are defined by domain experts, and can be reused across projects and applications. The potential for reuse and the resulting cost savings is enormous and easily justifies some extra effort in the modelling phase to make the models more complete.
FNR Pearl Chair. Head of the Software Engineering RDI Unit at LIST. Affiliate Professor at University of Luxembourg. More about me.
Tricia, my experience with getting value from OCL includes:
A) The pain is getting the rules agreed in English! Not many places do that, and this process forces the “business” to do that. This is great because the traditional approaches (especially Agile?) let them get away with ambiguous, un-written definitions. Traditional methods dont encourage them into a consensus.
B) Writing rules in a structured way has the perhaps un-expected benefit of increasing the quality of the rules as originally expressed in English. It makes you look like an expert when you go back to the business with “Do you actually mean XXX or XXY when you say that?”, when all you have tried to do is write the OCL and can’t work out which attribute they actually mean.
C) The ability to re-use the rules increases exponentially. Once the rules are visible, correct and rigorously defined, you keep finding places you can re-use them. I see you derive Java to validate data against the rules. I love to be able to output the rules into business requirement and functional specs. Developers in the ETL space love them. Testers love them. Front end form developers love them. We all love them!
Actually, that’s not right – some people hate them. Tricia, do you have any experience in teaching people OCL? Even experience BA types who know SQL and Java seem to think of it as too complex.
About teaching OCL: One thing that works for me is to show a small UML model and start addind some OCL expressions on it ( constraints, derivation rules, query operations,…) without explaining the language first.
The idea is to make them realize that intuitively they can (with a little help from me but very basic) guess the meaning. After than, they are not scared anymore and accept better the real complex parts of the language.
Hi Greg,
I agree with Jordi. The best way to introduce people to OCL is to show them some OCL in a model. Ideally it should be a model they know and understand. So we always try to train people using their own models. They discover that they can understand the rules, and also that the rules capture some of their domain knowledge very effectively. In fact, once we show them OCL on their own model in a training class, we often find people disagreeing over what the rule ought to be. It turns out that the same team often don’t have a shared understanding of the rules!
Another thing we find is that the type of rules you need to write on a model are mostly of the same form. So once you provide examples of the main ‘types’ of rules for a model, most users can ‘author’ new rules by using copy and paste.
And of course, what really gets people hooked on writing the OCL is that we allow them to execute and test the rule they write. They can prepare snippets of XML that ‘exercise’ the rule, and within MagicDraw they can ‘Validate XML’ and check that the OCL actually does what they expect. The teams working on the ‘specs’ can now execute the rules, and get the satisfaction that developers get when they see their code working…
Tricia, sounds sensible. If I want to try, can you point me to something? Greg
Hi Greg,
If you are a MagicDraw user and want to check this out on your own, download an evaluation copy of our Cameo OCL Transformer for MagicDraw from the NoMagic site: http://www.nomagic.com/products/magicdraw-addons/cameo-ocl-transformer.html. We include sample projects. You can execute the OCL in the sample projects against sample XML data that we provide.
Or we can schedule an online demo or webinar. Just contact us at [email protected].
Tricia
Watch a recording of the webinar at http://nomos-software.com/resources/webinars