[Fwd: Re: Optional attributes]



Date view Thread view Subject view Author view Attachment view

From: Shane Sendall (sendall@acm.org)
Date: Wed 19 May 2004 - 12:30:55 BST


Hi all,
Just an addition to what I wrote.
There is another case when you don't want a runtime exception and that 
is when you use the oclIsUndefined() operation.
For example, it may be more convenient to write:
let x : X = colOfXs->any() in
  if x.oclIsUndefined() then
    ....
  else
    ....
  endif

than
let x : X = colOfXs->any() in
   if colOfXs->size = 1 then
    ....
  else
    ....
  endif

Cheers,
    Shane

-------- Original Message --------
Subject: 	Re: Optional attributes
Date: 	Wed, 19 May 2004 13:13:31 +0200
From: 	Shane Sendall <sendall@acm.org>
To: 	puml-list@cs.york.ac.uk
References: 	<200405172032.i4HKWWVA025222@chico.cs.colostate.edu> 
<20040518145914.GA30668@purcell.dcs.kcl.ac.uk> 
<40AA2EEF.5090705@acm.org> <40AB0CE8.11D6A2C6@icmgworld.com> 
<40AB1BAA.3030407@acm.org> <40AB23A0.6603FF32@icmgworld.com>



Hi Shashank,
My take on OclUndefined is that it is an indicator for ill-formed 
expressions, e.g., x/0, some (detectable) logic contradiction, calling 
the 'any' operation on an empty collection, etc. As static errors are 
picked up before runtime, OclUndefined is only really associated to 
runtime errors.
Now the question arises as to why one would want a value for being 
ill-formed, why not just let the runtime crash the party and throw a 
runtime exception. And the only thing that leads one in this direction 
is the case where being undefined is ok. In OCL, it is ok to be 
undefined if you are in a larger expression with an 'or' logic operator 
and 'true' as the other operand, or with an 'and' operator and 'false' 
as the other operand, etc. Outside of these cases, you want the runtime 
to throw an exception.

Cheers,
    Shane

Date view Thread view Subject view Author view Attachment view