Chapter 5. Contracts

Once we've defined the structure of your language, this next step will show how to add constraints specified inside your language. Constraints on metamodels are static semantic. For instance you may add well formedness rules (contracts) to control errors made by users.

Thanks to aspect weaving, Kermeta allows you to reopen ecore class definition in order to add pre/post condition into it so as to satisfy the specified constraints. You only have to weave these pre/post-conditions (for instace adding some invariants) and call the method checkAllInvariant() on the root element of the model to check the contract.

[Tip]Tip

These constraints can also be expressed in Object Constraint Language (OCL) which is the Object Management Group (OMG) official language. You can import them merely by calling these methods. Kermeta offer the same easy navigation inside existing model in OCL (<Collection>.each, <Collection>.forAll, ...).

[Note]Note

Examples of how to add contract to your ecore model can be reached in the examples below :