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

Slides:



Advertisements
Similar presentations
Design by Contract.
Advertisements

CS101: Introduction to Computer programming
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
© 2010 Bennett, McRobb and Farmer1 Use Case Description Supplementary material to support Bennett, McRobb and Farmer: Object Oriented Systems Analysis.
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
© 2010 Bennett, McRobb and Farmer1 Requirements Analysis 1: Requirements and Classes Based on Chapter 7 of Bennett, McRobb and Farmer: Object Oriented.
Chapter 4 Enterprise Modeling.
SYSTEM ANALYSIS & DESIGN (DCT 2013)
Systems Analysis and Design 9th Edition
ITEC113 Algorithms and Programming Techniques
Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall Process Specifications and Structured Decisions Systems Analysis and Design, 8e Kendall.
Software Testing and Quality Assurance
Systems Analysis and Design in a Changing World, Fourth Edition
Chapter 9 Describing Process Specifications and Structured Decisions
Chapter 9 Describing Process Specifications and Structured Decisions Systems Analysis and Design Kendall & Kendall Sixth Edition © 2005 Pearson Prentice.
Chapter 9 Describing Process Specifications and Structured Decisions
Software Testing and Quality Assurance
Detail Design Extending UML and Object Design. Object Design.
© 2005 Prentice Hall4-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
03/12/2001 © Bennett, McRobb and Farmer Object Interaction Based on Chapter 9 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and.
Data and Process Modeling
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
University of Toronto Department of Computer Science © Steve Easterbrook. This presentation is available free for non-commercial use with attribution.
Computer Science 1620 Programming & Problem Solving.
03/12/2001 © Bennett, McRobb and Farmer Activity Diagrams Based on Chapter 5 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and.
University of Toronto Department of Computer Science © Castro, Mylopoulos and Easterbrook Lecture 12: Modelling Business Rules & Processes Ü Review.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
© Bennett, McRobb and Farmer Specifying Operations Based on Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design.
Object Specification Moving towards a more precise specification of software.
03/12/2001 © Bennett, McRobb and Farmer Use Case Diagrams Based on Chapter 6 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and.
Chapter 3 Planning Your Solution
Data flow diagrams.
System Implementation System Implementation - Mr. Ahmad Al-Ghoul System Analysis and Design.
Chapter 9 Describing Process Specifications and Structured Decisions
Phase 2: Systems Analysis
1 COSC 4406 Software Engineering COSC 4406 Software Engineering Haibin Zhu, Ph.D. Dept. of Computer Science and mathematics, Nipissing University, 100.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Describing Process Specifications and Structured Decisions Systems Analysis and Design, 7e Kendall & Kendall 9 © 2008 Pearson Prentice Hall.
WXGC6102: Object-Oriented Techniques Specifying Operations References: Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Conceptual Modelling – Behaviour
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
9-1 © Prentice Hall, 2007 Chapter 9: Analysis Classes Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey.
1 CSE323 การวิเคราะห์และออกแบบระบบ (Systems Analysis and Design) Lecture 07: Object Interaction and Specifying Operations.
© 2010 Bennett, McRobb and Farmer1 Requirements Analysis 2: Realizing Use Cases Based on Chapter 7 of Bennett, McRobb and Farmer: Object Oriented Systems.
The Software Development Process
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Systems Analysis and Design in a Changing World, Fourth Edition
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Systems Analysis and Design 8th Edition
7-1 © Prentice Hall, 2007 Topic 7: Analysis Classes Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey.
The Hashemite University Computer Engineering Department
Algorithms and Pseudocode
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Copyright © 2011 Pearson Education Process Specifications and Structured Decisions Systems Analysis and Design, 8e Kendall & Kendall Global Edition 9.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
1 Software Engineering: A Practitioner’s Approach, 6/e Chapter 11b: Component-Level Design Software Engineering: A Practitioner’s Approach, 6/e Chapter.
1 Object Oriented Analysis and Design System Events & Contracts.
Analysis Classes Unit 5.
About the Presentations
Algorithm and Ambiguity
Programming Languages 2nd edition Tucker and Noonan
Algorithm and Ambiguity
Understanding Problems and how to Solve them by using Computers
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Chapter 11 Describing Process Specifications and Structured Decisions
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

© 2010 Bennett, McRobb and Farmer1 Specifying Operations Based on Chapter 10 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design Using UML, (4th Edition), McGraw Hill, 2010.

2© 2010 Bennett, McRobb and Farmer In This Lecture You Will Learn: Why operations need to be specified What is meant by “Contracts” Non-algorithmic ways of describing operations: –Decision Tables –Pre- and Post-Condition Pairs Algorithmic ways of describing operations: –Structured English and Pseudocode –Activity Diagrams –Object Constraint Language

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

4© 2010 Bennett, McRobb and Farmer Operations and Their Effects 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 Some operations have no side-effects: –They return data but do not change anything

5© 2010 Bennett, McRobb and Farmer Services Among Objects When objects collaborate, one object typically provides a service to another 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© 2010 Bennett, McRobb and Farmer Contracts: an Approach to Defining Services A service can be defined as a contract between the participating objects Contracts focus on inputs and outputs The intervening process is seen as a black box, with irrelevant details hidden This emphasises service delivery, and ignores implementation

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

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

9© 2010 Bennett, McRobb and Farmer Non-Algorithmic Techniques Use when correct result matters more than the method used to reach it… …Or when no decision has yet been made about the best method –Decision tree: complex decisions, multiple criteria and steps (not described further here) –Decision table: similar applications to decision tree –Pre- and Post-Condition Pairs: suitable where precise logic is unimportant / uncertain

10© 2010 Bennett, McRobb and Farmer Decision Table Many variants, but all work by identifying: –Combinations of initial conditions = ‘rules’ –Outcomes that should result depending on what conditions are true = ‘actions’ Rules and actions are displayed in tabular form

11© 2010 Bennett, McRobb and Farmer 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 Tree Conditions to be tested Possible actions

12© 2010 Bennett, McRobb and Farmer Logically similar to decision table Identifies conditions that: –…must be true for operation to execute = pre- conditions –…must be true after operation has executed = post-conditions May be written in formal language (e.g. OCL) Pre- / Post-Condition Pair

13© 2010 Bennett, McRobb and Farmer Pre- / Post-Condition Pair: Change staff grade pre-conditions: creativeStaffObject is valid gradeObject is valid gradeChangeDate is a valid date gradeChangeDate is greater than or equal to today’s 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 - 1 day

14© 2010 Bennett, McRobb and Farmer Algorithmic Techniques Suitable where a decision can be made about the best method to use Can be constructed top-down, to handle arbitrarily complex functionality Examples: –Structured English –Activity Diagrams

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

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

17© 2010 Bennett, McRobb and Farmer Selection in Structured English 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

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

19© 2010 Bennett, McRobb and Farmer Structured English can be Arbitrarily Complex do while there are more staff in the list calculate bonus for this staff member begin case case bonus  £250 add name to ‘star of month’ list case bonus  £25 create warning letter end case store bonus amount end do format bonus list

20© 2010 Bennett, McRobb and Farmer do while there are more adverts for campaign get next advert get cost for this advert add to cumulative cost for campaign end do set total advert cost  final cumulative cost set total campaign cost  total advert cost  (total advert cost X overhead rate) get campaign budget if total campaign cost  campaign budget generate warning endif

21© 2010 Bennett, McRobb and Farmer Activity Diagrams Part of UML notation set Can be used for operation logic specification, among many other uses Easy to learn and understand Has the immediacy of graphic notation Some resemblance to old-fashioned flowchart technique

22© 2010 Bennett, McRobb and Farmer Example Activity Diagram: Check campaign budget [incorrect C ampaign] get Advert cost [more Adverts] [ correct Campaign] calculate Overheads [no more Adverts] show Campaign get Client

23© 2010 Bennett, McRobb and Farmer A formal language used for: –Precise definition of constraints on model elements –E.g. pre- and post-conditions of operations OCL statements can: –Define queries –Reference values –State business rules Object Constraint Language

24© 2010 Bennett, McRobb and Farmer Object Constraint Language Most OCL statements consist of: Context, Property and Operation 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 A property of that instance –Often an attribute, association-end or query operation

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

26© 2010 Bennett, McRobb and Farmer OCL expressionInterpretation context 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. context Person inv: self.savings >= 500 The property ‘savings’ of the person under consideration must be always be greater than or equal to 500. context 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. context Company inv: 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. context Company self.employee->select (age<60) The set of employees of a company whose age is less than 60.

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

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

29© 2010 Bennett, McRobb and Farmer References Bennett, McRobb and Farmer (2002) Yourdon (1989) covers Structured English and Pre- / Post-Conditions well Senn (1989) is good on Decision Tables 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)