Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Specify Constraint for Parameter of a UML Operation
Specify Constraint for Parameter of a UML Operation [message #1798041] Sun, 11 November 2018 16:52 Go to next message
Thomas Pusztai is currently offline Thomas PusztaiFriend
Messages: 27
Registered: September 2018
Junior Member
Hi,

I have a UML model and I would like to specify some constraints using OCL. Specifying invariants for classes works fine, but now I need to define a constraint on the parameter of an operation.

For example, let's suppose I have a class BankAccount with an operation executeTransfer(transfer: TransferDetails). A TransferDetails object contains the amount of money to be transferred and the destination of the transfer. How do I specify, e.g., that transfer.amount cannot be more than the current balance of the BankAccount?

I can create a preCondition for the executeTransfer() operation, but how do I access the attributes of the transfer parameter?
Re: Specify Constraint for Parameter of a UML Operation [message #1798077 is a reply to message #1798041] Mon, 12 November 2018 08:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
Hi

I don't see the problem so my answer has to be just do it. If you provided a repro comprising your metamodel and your best attempt at just doing it, I could see where you went wrong / why I don't understand the problem.

(Instinctively I would tend to define an Operation rather than a Parameter constraint; Parameter is getting a bit fine-grained. But UML decided to categorize Operation constraints as pre/post/body-conditions and AFAIAA USE is the only OCL tooling that does more than syntax check Operation conditions. A Parameter constraint might actually be a rather good idea.)

Regards

Ed Willink
Re: Specify Constraint for Parameter of a UML Operation [message #1798116 is a reply to message #1798077] Mon, 12 November 2018 19:32 Go to previous messageGo to next message
Thomas Pusztai is currently offline Thomas PusztaiFriend
Messages: 27
Registered: September 2018
Junior Member
Hi Ed,

Thank you for your response. Here is a class diagram of the example I talked about:
index.php/fa/34314/0/

I want to use a precondition for the executeTransfer() operation to make sure that the amount that should be transferred is not greater than the balance of the bank account.

I tried this:
self.transfer.amount >= self.owner.balance

Then I realized that, even though it is a precondition for the executeTransfer operation, the context of the expression seems to be the BankAccount class.

So I tried this:
self.executeTransfer.transfer.amount >= self.balance

This yields the following error message when trying to validate the model:

"Parsing error for Example::BankExample::BankAccount::executeTransfer::preExecuteTransfer::self.executeTransfer.transfer.amount >= self.balance: 
The 'executeTransfer::preExecuteTransfer' constraint is invalid: 'self.executeTransfer.transfer.amount >= self.balance' 1: Unresolved Property 'Example::BankExample::BankAccount::executeTransfer' 1: Unresolved Operation 'OclInvalid::>=(Real)'"


Best regards,
Thomas
Re: Specify Constraint for Parameter of a UML Operation [message #1798117 is a reply to message #1798116] Mon, 12 November 2018 21:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6440
Registered: July 2009
Senior Member
Hi

The precondition executes just the same as the operation.

Yes self is the context class. If you want to refer to a parameter, do not prefix it with self, just as in Java you would not use this.argument to access a function argument.

Regards

Ed Willink
Re: Specify Constraint for Parameter of a UML Operation [message #1798375 is a reply to message #1798117] Fri, 16 November 2018 11:02 Go to previous message
Thomas Pusztai is currently offline Thomas PusztaiFriend
Messages: 27
Registered: September 2018
Junior Member
Hi,

Sorry for my late response.

I tried out your suggestions today and with your hints I was able to figure out the correct statement:
transfer.amount >= self.balance


Thanks for your help!

Best regards,
Thomas
Previous Topic:"Create Dynamic Instance" in OCLinEcore tutorial
Next Topic:Initialise Map in OCL
Goto Forum:
  


Current Time: Sat Aug 24 11:03:28 GMT 2019

Powered by FUDForum. Page generated in 0.02121 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top