13.07.2015 Views

Object-Oriented Software Development with UML - UNU-IIST ...

Object-Oriented Software Development with UML - UNU-IIST ...

Object-Oriented Software Development with UML - UNU-IIST ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Contracts for System Operations 83describe what state changes that the operation commits to achieve.The contract of an operation is defined mainly in terms of its pre-conditions and post-conditions:Pre-conditions are the conditions that the state of the system is assumed to satisfy before the execu-=Post-conditions are the conditions that the system state has to satisfy when the execution operation=tion of the operation.has finished.In formal specification literature, the contract for an operation šŒM] ¤£ can be written as a Hoare-triple¬Pre-ConditionsšŒM¤£ ¬Post-Conditionsroughlymeaning that if the execution of šŒM] ¤£ starts from a state satisfying Pre-Condition, then when theexecution has finished, system will be in a state satisfying Post-Condition.Pre-Conditions and Post-condition are Boolean statements. A post-condition is a statement of what theworld should look like after the execution of an operation. For instance, if we define the operation “get-Square” on a number, the post condition would take the form E;NDASH…ZCr®¯CLbO°A1y±CLbO°A , where result is the outputand CLbO^A is the object on which the operation is invoked.A pre-condition is a statement of how we expect the world to be before the operation is executed. We mightdefine a pre-condition for the “getSquare” operation as CLbO°Â ²³®´ƒ . Such a pre-condition says that it is anerror to invoke “getSquare” on a negative number and the consequences of is undefined.Therefore, the pre-condition shall be checked either by the caller to ensure it is true before the execution,and/or checked the object executing the operation to flag an error when it is not true.As an example, consider the operation NDU_CXNDE:VWCXNDY‰ ¦H©M…Iµ m >›a{§HJRUsCTOTCTeªµVSU_CXǸ hNE£:Its pre-condition can be stated as UPC is known to the system.=its post-conditions include:=– If a new sale, a K+RZ[N was created (instance creation).– If a new sale, the new K+RZ[N was associated <strong>with</strong> the >—šxK œ (association formed).– A K+RZ[NWA:\ OLU+N9VWCXNY was created (instance creation).– The K+R§Z†NDA;\ OLU+NSVWCXNDY·„°§H•R§UsCTOLCTe was set to §HJRUsCTOTCTe (attribute modification).– The K+R§Z†NDA;\ OLU+NSVWCXNDY was associated <strong>with</strong> a >¥E¦?G§H•ICLK§M•N9IOPQI9R§CTÕ ?U , based on m >›amatch (associationformed).It is recommended to express post-conditions in the past tense, in order to emphasise they are declarationsabout a past state change, rather than about actions. For example, we had better to writeReport No. 259, July 2002<strong>UNU</strong>/<strong>IIST</strong>, P.O. Box 3058, Macau

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!