Two years after the previous version (OCL 2.2), the OMG has now released the new OCL version: OCL 2.3.1.
What’s new in this version? Well, not much, only a bunch of minor issues/typos that needed to be fixed. In fact, I’m not sure if this is a good thing or not. A standard that basically stops evolving for two years could mean that it’s very mature so there’s no need to do major changes or that nobody really cares so there’s no need to do major changes. Not sure whether OCL falls into reason 1 or 2. What´s your take?
FNR Pearl Chair. Head of the Software Engineering RDI Unit at LIST. Affiliate Professor at University of Luxembourg. More about me.
Well, using OCL regularly, makes you wish for certain improvements. QVTo adds certain shortcuts on top of OCL, that could be added to the core of OCL. One of the most annoying things is writing type filters on collections. In standard OCL you have to write myCollection->select(oclIsKindOf(NewType))->collect(oclAsType(NewType)). The makers of Acceleo added an own Collection::filter(Type) shortcut function to address this issue.
I suppose the ability to add your own collection operations makes sense in that context. For example:
context Collection(OclAny) def : filter(type : OclType) : Collection(OclAny) =
self->select(e | e.oclIsKindOf(type));
context Collection(OclAny) def : join(f : Lambda(OclAny, OclAny) : OclAny) : OclAny =
self->iterate(e; acc : OclAny = OclUndefined |
if acc.oclIsUndefined() then
e
else
f(acc, e)
endif
);
Sequence{‘one’, ‘two’, ‘three’}->join(x, y | x + ‘, ‘ + y)
This does pose problems for static type-checking, however. The first example takes a type as parameter, which means that the returned collection has elements of a type potentially only known at runtime (e.g. retrieved through x.oclType()).
The second example triggers the need for generic types, as it uses parametrised types.
N.B. Above examples are implemented in SimpleOCL, so they do actually work! However, SimpleOCL does not perform static type-checking, and avoids the raised issue that way ;-).