During syntax tree manipulation, common operations are often extracted to utility methods in order to simplify this task. It is possible to extract such utilities to static methods or create node wrappers with virtual methods. However, in MPS we have a better solution: behavior language aspect. It makes it possible to create virtual and non-virtual instance methods, static methods, and concept instance constructors.
Concept instance methods
A Concept instance method is a method which can be invoked on a specified concept instance. It is possible to have both virtual and non-virtual concept instance methods. Virtual methods can be overridden in extending concepts, but non-virtual methods cannot. A Virtual concept method can be declared abstract, which means that it should be implemented in one of its inheritors.
Concept instance methods can be implemented both in concept declarations and in concept interfaces. When MPS decides which virtual method to invoke in inheritance hierarchy, the following algorithm is applied:
- If a current concept implements a method, invoke it. Return computed value.
- Invoke algorithm for extended concept if there is one. In case of success return computed value.
- Invoke algorithm for all implemented concept interfaces. In case of success return computed value.
- Return failure.
Concept constructors
When a concept instance is created, it is often a good idea to initialize some properties/references/children to default value. Concept constructors can be used for this task. The code inside the concept construction is invoked on each instantiation of a new node of a particular concept.
Concept static methods
Some utility methods cannot be created as an instance method. For this case, MPS has static concept methods.Constraints
Add Comment