Problem:
ObjectExp seems to be an enhancement to the InstantationExp due to the additional semantics, however it gets limited due to the fact that every time we need to use it we have to define the constructor body (in constrast to the instantiation expression usage). Although, ObjectExp was conceived to inline object instantiations, this limitation is not justified.
However, this limitation could be removed by also allowing an ObjectExp-Constructor combination, in the same way we have for InstantiationExp. The problem relies on a flaky concrete syntax which we could enhance to exploit an ObjectExp with an already defined constructor operation:
constructor Column::ColumnConstructor (n:String,t: String)
{ name:=n; type:=t; }
object result1 : Column (“name”, “String”);
object result2 : Column (“age”, “Integer”);
Providing a constructor body (from ObjectExp) and a list of arguments (from InstantiationExp) should be prohibited in both, the concrete syntax and the abstract syntax. Regarding the abstract syntax this could be expression with a constraint.
context ObjectExp
inv : argument->size() > 0 implies body.oclIsUndefined()
Discussion:
This enhancement seems convenient with no apparent drawbacks, since the old ObjectExp usage remains valid.
Proposed solution:
In section 8.2.1.24 add the following subsection:
Constraints
If an object expression contains a constructor body, no arguments for a constructor are allowed (and vice versa):
context ObjectExp
inv: argument->notEmpty() > 0 implies body.oclIsUndefined() and
not body.oclIsUndefined() implies argument->isEmpty()
In section 8.2.1.24 add the following to the the end notation subsection:
Similarly to InstantiationExp, an object expression could be used to invoke a constructor operation, rather than inlining a constructor body:
object result1 : Column (“name”, “String”);
object result2 : Column (“age”, “Integer”);
Note that this notation allows us to use object expression to instantiate (or update) objects, while having a reusable constructor in order to initialize (or update) the properties of the object subject to be created (or updated).
In section 8.4.7:
Replace:
<object_exp> ::= 'object' ('(' <iter_declarator> ')')? <object_declarator>
<expression_block>
By:
<object_exp> ::= 'object' ('(' <iter_declarator> ')')? <object_declarator>
(<expression_block> | '(' (<declarator_list>)? ')' )