Skip to main content
Jump to: navigation, search

ATL/Design Patterns

Revision as of 05:17, 28 February 2015 by (Talk | contribs)

This page describes various design patterns that are specific to the use of ATL.


If you find yourself executing the following code many times, the Mapped-By pattern may be useful to you:

 METAMODEL!MetaClass.allInstances()->any(e | =

This code is expensive if executed more than once, because it has to iterate over all instances of METAMODEL!MetaClass every time (O(n)). Instead, you can create a Map that indexes all instanced by their requested property:

 helper def : metaClassByProperty : Map(OclAny, METAMODEL!MetaClass) =
   METAMODEL!MetaClass.allInstances()->iterate(e; acc : Map(OclAny, METAMODEL!MetaClass) = Map{} |
     acc->including(, e)

Building the Map still runs in O(n), but after that, you can write the initial code as follows:


Because this is a hash map lookup, it runs in O(1).

Back to the top