3

Working on a timereport project in MDriven and I have created an instance where an employee has worked ten hours. The Employee class's "attribute.type" is of "timespan" for "HoursWorked".

action:
Employee.create
Employee.allinstances->at0(0) .HoursWorked:= 10:00:00

This code gives me a syntax error. Is the at0 not functioning with "timespan"? If so, which expression should be used in this case to create a certain timespan?

Also, if anyone knows a good, informative wiki with all the OCL expressions and how to correctly write syntax that would be much aprreciated.

Ed Willink
  • 1,205
  • 7
  • 8
Gustaf
  • 147
  • 5

2 Answers2

2

The issue is that the MDriven action language (based on OCL but with side effects allowed) requires you to separate statements with ;

Try:

action:
Employee.create;  -- notice that semicolon
Employee.allinstances->at0(0).HoursWorked:= TimeSpan.Create(10,00,00)  --NO ; on end statement
Hans Karlsen
  • 2,275
  • 1
  • 15
  • 15
1

This question is titled OCL and so the following answer applies:

There is no allinstances in OCL; it is allInstances().

There is no at0() in OCL; it is at() and since OCL is a specification language indexes are 1-based, so a 0 index is invalid.

The OCL expressions and library operations are available in the OMG specification or the online Eclipse help: http://help.eclipse.org/oxygen/topic/org.eclipse.ocl.doc/help/StandardLibrary.html?cp=74_2

However it is clear that you are actually using a non-standard OCL embedded presumably in MDriven, so answers applicable to OCL may not be relevant.

Ed Willink
  • 1,205
  • 7
  • 8
  • I see. I think you're right that MDriven's OCL is possibly not standard since I've watched the developer's OCL tutorial ( https://wiki.mdriven.net/index.php/Part_2_OCL:_Operators ) whereupon I learned the implementations in the same style as shown in the video. – Gustaf Feb 11 '18 at 13:26
  • 1
    Ocl is a language - and it allows you to declare methods. Hence you cannot say that at0() is illegal. It is a just another method that adheres to its documented definition. – Hans Karlsen Feb 12 '18 at 17:53
  • Yes, but unfortunately the specification is very deficient; I'm working hard to remedy this. Extensibility as specified is very limited. ->at0() implies a new Collection operation for which there is no user extensibility. – Ed Willink Feb 12 '18 at 22:10
  • 1
    @EdWillink - point taken. With MDriven we are writing complete systems in OCL syntax and we have allowed ourselves to solve real practical problems by extending the operators. We stay true to the idea and syntax of OCL so I still firmly believe that OCL is a correct label on questions related to MDriven. – Hans Karlsen Feb 13 '18 at 08:59
  • 2
    OCL should certainly be adaptable but it must also be consistent. I considered whether at0 would be a good addition to the OCL ordered collections. From one useability point of view, yes, it avoids the user "+1"ing tediously. But once you move on to indexOf and subSequence, every indexed operator needs a "0" duplicate and users must then ensure that they use the right one. Bottom line, OCL made a 1-based design choice. Adding support for 0-based as well would make OCL a worse language so 0-based operations are not OCL. – Ed Willink Feb 13 '18 at 12:37