Re: Using OCL to declare operation



Date view Thread view Subject view Author view Attachment view

From: Alexandre Correa (alc@wnetrj.com.br)
Date: Thu 08 Apr 2004 - 16:12:30 BST


I think you'd better read the specification of the new OCL version (2.0). 
It contains a more in-depth explanation of the new OCL features (including 
def). http://www.omg.org/cgi-bin/doc?ptc/2003-10-14.

I will give you two examples extracted from the new book on OCL written by 
Jos Warmer and Anneke Kleppe (The Object Constraint Language Second Edition 
- getting your models ready for MDA), also an excellent reference on OCL.

-- defining a new attribute
context LoyaltyAccount
def: turnover : Real = transaction.amount->sum()
-- it is similar to defining an derived attribute on class LoyaltyAccount
-- the result is a new attribute stereotyped with <<OclHelper>>
-- syntax is context <Classifier> def: <att name> : <att type> = <ocl 
expression conforming to att type>

-- defining a new operation
context LoyaltyProgram
def: getServicesByLevel(levelName : String) : Set(Service) =
    levels->select(name = levelName).availableServices->asSet()
-- it is similar to defining a query operation on class LoyaltyAccount
-- the result is a new operation stereotyped with <<OclHelper>>
-- syntax is context <Classifier> def: <op name> (<op params>) : <return 
type> = <ocl expression conforming to returntype>

After having defined such attributes and operations, you can use them in 
any OCL expression as if it were defined directly in the UML model.


Hope this helps.

Alexandre


At 21:41 6/4/2004 +0530, you wrote:

>Referring to  UML specification March 2003 Version 1.5 formal/03-03-01
>
>In section
>6.4.3 Let Expressions and «definition» Constraints
>
>The let expression allows one to define an attribute or operation that
>can be used in the constraint.
>
>Does the explanation of above mentioned line exists somewhere?
>
>Thanks in advance,
>Shashank
>
>
>
>
>To remove yourself from this list please mail puml-list-request@cs.york.ac.uk
>with a message containing the word "unsubscribe".

Date view Thread view Subject view Author view Attachment view