oclformal-methodspost-conditions

Equivalence of if-then and implies in OCL statements


Are the following two OCL statements equivalent for some function context?

post: if a > 0 then b < c

post: b < c implies a > 0


Solution

  • No.

    In OCL, the construct is if ... then ... else ... endif so your first example can only be 'equivalent' to a different syntax error.

    The logical operations are rewritable using if constructs, but considerable care is necessary to ensure that the possibilities with null or invalid inputs do not crash the if condition term which must be a 2-valued Boolean.