Can an OCL Post condition be inside an if then statement?

I'm new to OCL and I have some doubts about how the pre and postconditions work.

Can a post condition be placed inside an if then statement?

For example, the following piece of code is valid or I'm just mixing concepts?

Context [some context here]
if ( 
... some conditions...
) then ( 
result = 1
post: self.isComplete() -- for example
)
endif

Thank you very much for your help

Answers


I would rewrite it as:

Context MyContext :: Integer
    post :
        if <some condition>
        then
            result = 1
        endif

If you need more condition you can do this with:

Context MyContext :: Integer
    post :
        if <some condition>
        then
            -- Another condition
            if self.isComplete()
            then
                result = 1
            else
               result = 0
            endif
        else
            result = 0
        endif

You could use implies operator like below:

context k 
inv
(k.count=0)implies(k.status='nothing')

Need Your Help

PYTHON/OUTLOOK Sending e-mails through PYTHON with DOCX

python email outlook

I have to send mails through python. It works. It is almost done. The only problem is that I have to keep the formatting too. So either I have to send e mail as HTML (and then rewrite template with...

Maximum in a List

prolog

I have a list and each element of the list has five components, so the list would be something like [[1,3,4,5,6], [2,4,5,15,16],...].