The oclSingleton ocl operator

This article was moved to MDriven Wiki The oclSingleton ocl operator

There is an operator in ocl that I bet you do not know about yet: oclSingleton.

Use it like this: Class1.oclSingleton <and follow with operations or navigations on that single instance>

If Class1 does not have an instance at the time of executing the oclSingleton, one is created.

In order for you to be allowed to use this you must set the taggedvalue on Class1 “Eco.IsSingleton” to “true”

It is a very practical design pattern to a have a modeled Singleton class – this removes the need for other global variables – like logged in user etc. Since the Singleton class can have code derived attributes and associations you can pick up important info from the running environment and make them available in the model context – try it – it will make your code less hairy.

This entry was posted in OCL, UML. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.