Presentation is loading. Please wait.

Presentation is loading. Please wait.

© Bennett, McRobb and Farmer 2002 1 Specifying Operations Based on Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design.

Similar presentations


Presentation on theme: "© Bennett, McRobb and Farmer 2002 1 Specifying Operations Based on Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design."— Presentation transcript:

1 © Bennett, McRobb and Farmer 2002 1 Specifying Operations Based on Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design Using UML, (2 nd Edition), McGraw Hill, 2002.

2 © Bennett, McRobb and Farmer 2002 2 In This Lecture You Will Learn: n About the role of operation specifications n What is meant by “Contracts” n About algorithmic and non-algorithmic techniques, and how they differ n How to use: –Decision Tables –Pre- and Post-condition Pairs –Structured English –Activity Diagrams –Object Constraint Language

3 © Bennett, McRobb and Farmer 2002 3 Why We Specify Operations n From analysis perspective: –Ensure users’ needs are understood n From design perspective: –Guide programmer to an appropriate implementation (i.e. method) n From test perspective: –Verify that the method does what was originally intended

4 © Bennett, McRobb and Farmer 2002 4 Types of Operation and Their Effects n Operations with side-effects may: –Create or destroy object instances –Set attribute values –Form or break links with other objects –Carry out calculations –Send messages or events to other objects –Any combination of these n Operations without side-effects are pure queries –Request data but do not change anything

5 © Bennett, McRobb and Farmer 2002 5 Services Among Objects n When objects collaborate, one object typically provides a service to another n Examples: –A Client object might ask a Campaign object for its details –The same Client object might then ask a boundary object to display its related Campaign details to the user

6 © Bennett, McRobb and Farmer 2002 6 Contracts: an Approach to Defining Services n A service can be defined as a contract between the participating objects n Contracts focus on inputs and outputs n Intervening process is seen as a black box n Irrelevant details are hidden n This emphasizes service delivery, and ignores implementation

7 © Bennett, McRobb and Farmer 2002 7 Contract-Style Operation Specification n Intent or purpose of the operation n Operation signature, including return type n Description of the logic n Other operations called n Events transmitted to other objects n Any attributes set n Response to exceptions (e.g. an invalid parameter) n Non-functional requirements (adapted from Larman, 1998 and Allen and Frost, 1998)

8 © Bennett, McRobb and Farmer 2002 8 Types of Logic Specification n Logic description is probably the most important element n Two main categories: n Algorithmic types are white box—they focus on how the operation might work n Non-algorithmic types are black box— they focus on what the operation should achieve

9 © Bennett, McRobb and Farmer 2002 9 Non-Algorithmic Techniques n Appropriate where correct result matters more than method to arrive at it n Decision tree: complex decisions, multiple criteria and steps (not described further here) n Decision table: similar applications to decision tree n Pre- and Post-condition pairs: suitable where precise logic is unimportant or uncertain

10 © Bennett, McRobb and Farmer 2002 10 Conditions and actionsRule 1Rule 2 Rule 3 Conditions Is budget likely to be overspent?NYY Is overspend likely to exceed 2%?-NY Actions No actionX Send letter XX Set up meeting X Example Decision Table

11 © Bennett, McRobb and Farmer 2002 11 Pre- and Post-condition Pair pre-conditions: creativeStaffObject is valid gradeObject is valid gradeChangeDate is a valid date post-conditions: a new staffGradeObject exists new staffGradeObject linked to creativeStaffObject new staffGradeObject linked to previous value of previous staffGradeObject. gradeFinishDate set equal to gradeChangeDate

12 © Bennett, McRobb and Farmer 2002 12 Algorithmic Techniques n Suitable where users understand the procedure for arriving at a result n Can be constructed top-down, to handle arbitrarily complex functionality n Examples: –Structured English –Activity Diagrams

13 © Bennett, McRobb and Farmer 2002 13 Structured English n Commonly used, easy to learn n Three types of control structure, derived from structured programming: –Sequences of instructions –Selection of alternative instructions (or groups of instructions) –Iteration (repetition) of instructions (or groups of instructions)

14 © Bennett, McRobb and Farmer 2002 14 Sequence in Structured English n Each instruction executed in turn, one after another get client contact name sale cost = item cost * ( 1 - discount rate ) calculate total bonus description = new description

15 © Bennett, McRobb and Farmer 2002 15 Selection in Structured English n One or other alternative course is followed, depending on result of a test: if client contact is ’Sushila’ set discount rate to 5% else set discount rate to 2% end if

16 © Bennett, McRobb and Farmer 2002 16 Iteration in Structured English n Instruction or block of instructions is repeated –Can be a set number of repeats –Or until some test is satisfied, for example: do while there are more staff in the list calculate staff bonus store bonus amount end do

17 © Bennett, McRobb and Farmer 2002 17 Activity Diagrams n Are part of UML notation set n Can be used for operation logic specification, among many other uses n Are easy to learn and understand n Have the immediacy of graphical notation n Bear some resemblance to old- fashioned flowchart technique

18 © Bennett, McRobb and Farmer 2002 18 Link to CreativeStaff Create new StaffGrade Link to previous StaffGrade Set previous StaffGrade gradeFinishDate Simple Activity Diagram

19 © Bennett, McRobb and Farmer 2002 19 Check approval for grade change [approved by Director] [not approved by Director] Print approval request Link to CreativeStaff Create new StaffGrade Link to previous StaffGrade Set previous StaffGrade gradeFinishDate Activity Diagram with Selection

20 © Bennett, McRobb and Farmer 2002 20 Calculate bonus [bonus > £250] Add to list [more StaffMembers] Format list [no more StaffMembers] Add to ‘star’ list Create warning letter [bonus < £25] [bonus >= £25 AND bonus <= £250] Activity Diagram with Selection and Iteration

21 © Bennett, McRobb and Farmer 2002 21 Object Constraint Language n Most OCL statements consist of: –Context, Property and Operation n Context –Defines domain within which expression is valid –Instance of a type, e.g. object in class diagram –Link (association instance) may be a context n A property of that instance –Often an attribute, association-end or query operation

22 © Bennett, McRobb and Farmer 2002 22 n OCL operation is applied to the property n Operations include –Arithmetical operators *, +, - and / –Set operators such as size, isEmpty and select –Type operators such as oclIsTypeOf

23 © Bennett, McRobb and Farmer 2002 23 OCL expressionInterpretation Person self.gender In the context of a specific person, the value of the property ‘gender’ of that person — i.e. a person’s gender. Person self.savings >= 500 The property ‘savings’ of the person under consideration must be greater than or equal to 500. Person self.husband->notEmpty implies self.husband.gender = male If the set ‘husband’ associated with a person is not empty, then the value of the property ‘gender’ of the husband must be male. Boldface denotes OCL keyword, but has no semantic import. Company self.CEO->size <= 1 The size of the set of the property ‘CEO’ of a company must be less than or equal to 1. That is, a company cannot have more than 1 Chief Executive Officer. Company self.employee->select (age < 60) The set of employees of a company whose age is less than 60.

24 © Bennett, McRobb and Farmer 2002 24 OCL Used for Pre- and Post-conditions context CreativeStaff::changeGrade (grade:Grade, gradeChangeDate:Date) pre: grade oclIsTypeOf(Grade) gradeChangeDate >= today post: self.staffGrade[grade]->exists self.staffGrade[previous]->notEmpty self.staffGrade.gradeStartDate = gradeChangeDate self.staffGrade.previous.gradeFinishDate = gradeChangeDate

25 © Bennett, McRobb and Farmer 2002 25 Summary In this lecture you have learned about: n The role of operation specifications n What is meant by “Contracts” n Algorithmic and non-algorithmic techniques, and how they differ n How to use: –Decision Tables, Pre- and Post-condition Pairs, Structured English, Activity Diagrams and Object Constraint Language

26 © Bennett, McRobb and Farmer 2002 26 References n Bennett, McRobb and Farmer (2002) n Yourdon (1989) covers Structured English and Pre- and Post-conditions well n Senn (1989) is good on Decision Tables n Larman (1998) takes a contract-based approach to O-O analysis and design, with examples taken to Java code (For full bibliographic details, see Bennett, McRobb and Farmer)


Download ppt "© Bennett, McRobb and Farmer 2002 1 Specifying Operations Based on Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design."

Similar presentations


Ads by Google