11 Contracts CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, 1990. (Chapter 6)

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
© 2005 by Prentice Hall Appendix 3 Object-Oriented Analysis and Design Modern Systems Analysis and Design Fourth Edition Jeffrey A. Hoffer Joey F. George.
Chapter 26 Legacy Systems.
Chapter 7 System Models.
Chapter 1 The Study of Body Function Image PowerPoint
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 1 Embedded Computing.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 7 System Design Techniques.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 5 Author: Julia Richards and R. Scott Hawley.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
1 Chapter 40 - Physiology and Pathophysiology of Diuretic Action Copyright © 2013 Elsevier Inc. All rights reserved.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
1 9 Moving to Design Lecture Analysis Objectives to Design Objectives Figure 9-2.
Making the System Operational
ZMQS ZMQS
Week 2 The Object-Oriented Approach to Requirements
Requirements Diagrams With UML Models
BT Wholesale October Creating your own telephone network WHOLESALE CALLS LINE ASSOCIATED.
Local Services and Swipe Card Chapter 5. Local Services and Swipe Card 5-2 Objectives Add Local Services Load Services from Other Swipe Card Systems Demo.
Report Card P Only 4 files are exported in SAMS, but there are at least 7 tables could be exported in WebSAMS. Report Card P contains 4 functions: Extract,
ABC Technology Project
15-1 Copyright © 2013 Pearson Education, Inc. publishing as Prentice Hall Chapter 15 Money and Banking.
© Charles van Marrewijk, An Introduction to Geographical Economics Brakman, Garretsen, and Van Marrewijk.
© Charles van Marrewijk, An Introduction to Geographical Economics Brakman, Garretsen, and Van Marrewijk.
1 4 Square Questions B A D C Look carefully to the diagram Now I will ask you 4 questions about this square. Are you ready?
Software Requirements
Squares and Square Root WALK. Solve each problem REVIEW:
Systems Analysis and Design with UML Version 2.0, Second Edition
Executional Architecture
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
Week 1.
Chapter 10: The Traditional Approach to Design
Systems Analysis and Design in a Changing World, Fifth Edition
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
1 Unit 1 Kinematics Chapter 1 Day
Chapter 11 Describing Process Specifications and Structured Decisions
Copyright ©2013 Pearson Education, Inc. publishing as Prentice Hall
Chapter 11 Component-Level Design
CHAPTER 11 FILE INPUT & OUTPUT Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
1 PART 1 ILLUSTRATION OF DOCUMENTS  Brief introduction to the documents contained in the envelope  Detailed clarification of the documents content.
13-1 © Prentice Hall, 2004 Chapter 13: Designing the Human Interface (Adapted) Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra,
How Cells Obtain Energy from Food
Chapter 14 Writing and Presenting The Systems Proposal
Abstract Class, Packages and interface from Chapter 9
1 Abstract Class and Packages from Chapter 9 Lecture.
Modeling Main issues: What do we want to build How do we write this down.
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
Data Abstraction: The Walls
111 Subsystems CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 7)
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
CS Collaborations and Hierarchies CS 4311 Chapters 5 and 6 of Wirfs-Brock, R., Wilkerson, B., and Wiener, L., Designing Object- Oriented Software,
CS Collaborations and Hierarchies CS 4311 Chapters 5 and 6 of Wirfs-Brock, R., Wilkerson, B., and Wiener, L., Designing Object- Oriented Software,
111 Subsystems CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 7)
Collaborations and Hierarchies
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Presentation transcript:

11 Contracts CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 6)

22 Outline Contacts: what and why? Contract documentation Extension to CRC cards Collaboration graphs Guidelines for defining contracts

3 Review: Responsibility Responsibility: (what is this?)

4 Contract: What and Why? Responsibility: something an object (server) does for other objects (clients) Contract: set of cohesive responsibilities that a client can depend on Contract is not the same as responsibility Abstraction and analysis tool, e.g., for refining hierarchy and identifying subsystems

Server 5 Client and Server View A contract defines a set of requests that a client can make of a server. The server is guaranteed to respond to the request. Responsibilities are the basis for determining contracts. Client Contract 3

6 Example The class Chart has responsibilities for creating bar charts, pie charts, and line charts. The contract states that given a list of numbers and a chart type, the class will return a chart of the given type with the given numbers.

7 Question: Contracts in UML? Similar concept or notion in UML? Expressing contracts in UML?

8 Classes and Contracts A class can support any number of contracts. A responsibility may be part of at most one contract. Not all responsibilities will be part of a contract (i.e., there are private responsibilities). Contracts are used in a collaboration.

9 Collaboration Graphs Drawing Editor Drawing 1 Figure Set Arrow from client to a contract supported by the server. One numbered semicircle for each contract. If two objects collaborate with a class by means of a contract, they point to the same semicircle.

10 Contract Documentation Class Superclass Description: Contracts: Private Responsibilities

11 Contract Documentation Class Superclass Description: Contracts: Private Responsibilities Number these sequentially for each class. Be careful of inheritance: subclasses inherit from super classes.

12 Example Class: Form Superclass: UserInteraction Description: Provide human interface for data input Contracts: 4. Get Numeric Value from User Ask user for informationDisplayScreen (7) Know if user responded Know users responseKeypad Provide feedback to userDisplayScreen (8) Private Responsibilities: Know form contents Note the contract number for collaboration

13 Guidelines for Defining Contracts Group responsibilities used by the same clients Maximize cohesiveness of classes Minimize the number of contracts

14 Guideline 1 Group responsibilities used by the same clients. One way to find a contract, a set of cohesive responsibilities When a set of responsibilities is used by the same client, They may be detailed views of a single service They may be part of one contract.

15 Example 1 An Array class has two responsibilities likely to be used by the same client: Return subset of elements that meet specified criterion Return first element that meets specified criterion Contract: select elements based on specified criterion

16 Example 2 An Employee class has two clients: Record needing general employee information Payroll needing salary-related information Create two different contracts Contract 1: Provide general employee information Contract 2: Provide salary information

17 Guideline 2 Maximize cohesiveness of classes. To make class hierarchy easier to refine by maximizing cohesiveness of contracts Look for server offering some abstract service to a variety of clients Example: A Reader class can read from keyboard, file, network, …

18 Example Suppose that arrays support a contract for element-wise arithmetic operations. Q1: Appropriate behavior for arrays? Any array containing elements for which multiplication is meaningless? Q2: Solution?

19 Guideline 3 Minimize number of contracts. Why?

20 Guideline 3 (Cont.) Provide a general interface so that clients do not have to know about implementations Look for similar responsibilities that can be generalized Use polymorphism Define contracts for classes at the top of hierarchy Add new contracts only for subclasses that add new functionality

21 Balance Conflicting Goals Design small, easily understood and reusable classes Design a small number of classes with easily understood relationships Use your understanding of cohesion, coupling and inheritance to find the balance point.

22 Summary A contract is a set of cohesive responsibilities. A class should support a cohesive set of contracts. Minimize number of contracts supported by each class.

23 Group work and Assignment Group work (handout) Assignment: Define and document contracts for the project Due: Oct. ?, 2013 (part of subsystems)