🚀 Welcome to MDriven Learn –  Don’t miss the latest Release Notes.
Default string representation and asString

You can use asString on all objects in OCL (the same way as you can in C#, for example).

When you use asString, the DefaultStringRepresentation is used to get the result string.

Note on Performance

asString and the DefaultStringRepresentation are not subscribed. This means that every time asString is used, it needs to be reevaluated. For better performance, create a derived attribute—for example, "Presentation" with the OCL—and use self.Presentation in DefaultStringRepresentation.

Also, avoid using asString in other expressions that need to have high performance because they cannot subscribe properly if you use asString in the expression tree.

Keyword: Defaultstringrepresentation, asString