CRC: Classes, Responsibilities, and Collaborations

Slides:



Advertisements
Similar presentations
ACM/JETT Workshop - August 4-5, :Design of Classes using CRC cards.
Advertisements

1 Introduction to CRC Cards CRC Card = Class Responsibility Collaborator Card Invented in 1989 by Kent Back and Ward Cunningham The CRC Card Book by D.Bellin.
11 Contracts CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 6)
From use cases to classes (in UML). A use case for writing use cases Use case: writing a use case Actors: analyst, client(s) Client identifies and write.
1 Object-oriented design Part 2: OO tools & UML. 2 CRC cards Design tool & method for discovering classes, responsibilities, & relationships Record on.
Object Design Examples with GRASP
Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
1 Classes. 2 Finding classes w Choosing classes is first step in defining essence of problem w If you can recognize an abstraction, you’ve found a candidate.
Lecture 4 Class Responsibility Collaboration Cards
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
CRC Card By: Yusmadi Yah Jusoh. What is CRC card?  A Class Responsibility Collaborator (CRC) model (Beck & Cunningham 1989; Wilkinson 1995; Ambler 1995)
Domain Modeling (with Objects). Motivation Programming classes teach – What an object is – How to create objects What is missing – Finding/determining.
Object-Oriented Systems Analysis and Design Using UML
111 Subsystems CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 7)
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
CS212: Object Oriented Analysis and Design Lecture 4: Objects and Classes - I.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Chapter 17 GRASP: Designing Objects with Responsibilities. 1CS6359 Fall 2011 John Cole.
Slide 1 Structural Modeling Chapter 7. Slide 2 Key Ideas A structural or conceptual model describes the structure of the data that supports the business.
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,
Chapter 18 Object-Oriented Systems Analysis and Design Using UML
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Class Diagrams Identifying and representing Classes Object Web, Bapayya Choudhary Maganti.
CS Overview of CRC CS 4311 B. Beck and W. Cunningham, A Laboratory for Teaching Object-Oriented Thinking, OOPSLA ’89, October 1-6, R. Wirfs-Brock,
CS Collaborations and Hierarchies CS 4311 Chapters 5 and 6 of Wirfs-Brock, R., Wilkerson, B., and Wiener, L., Designing Object- Oriented Software,
1 What is OO Design? OO Design is a process of invention, where developers create the abstractions necessary to meet the system’s requirements OO Design.
CRC – What is it?  Class  Responsibilities  Collaborations.
Lecture OO05 Object Scenarios Object Interaction Diagrams
1 Class responsibilities & relationships. 2 Responsibilities Responsibilities describe a class’s purpose in terms of its functionality Responsibilities.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Lecture 18: Object-Oriented Design
ITEC324 Principle of CS III Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
Phase 6 Start: Saturday14 April End: Saturday 21 April
111 Subsystems CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 7)
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
User Interface Design Make Your Program Easy to Use and Look Good.
Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
1 Case Study and Use Cases for Case Study Lecture # 28.
Use Case Modeling - II Lecture # 27.
ATM OO Design and Implementation Case Study
System Design Ashima Wadhwa.
Conception OBJET GRASP Patterns
Dynamic Modeling of Banking System Case Study - II
Introduction to Triggers
Chapter 1 Data Abstraction: The Walls
Collaborations and Hierarchies
DESIGN MODEL: USE-CASE REALIZATIONS WITH GRASP PATTERNS
OO Domain Modeling With UML Class Diagrams and CRC Cards
INTRODUCTION TO OOP Objective:
NACE Committee Workspace (NCW)Training Balloting
Object-Oriented Analysis
Ch 15 –part 3 -design evaluation
Overview of managing access for a Bill to ID
Chapter 11 Following the Trail; Examining Execution Sequences
CRC Modeling (class-relationship-collaborator)
Patterns.
ResponseCard XR Changing Channels
Slides by Steve Armstrong LeTourneau University Longview, TX
Revision of Simple troubleshooting
ResponseCard XR Changing Channels
CRC Card Design A CRC Model is a collection of cards (usually standard index cards or larger) that are divided into three sections. 1. Class 2. Responsibility.
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
4: Object-oriented Analysis & Design
Object Oriented Analysis and Design
Chapter 22 Object-Oriented Systems Analysis and Design and UML
KEYPAD INSTRUCTIONS.
ITEC324 Principle of CS III
ITEC324 Principle of CS III
Object Oriented System Design Responsibilities
Presentation transcript:

CRC: Classes, Responsibilities, and Collaborations CS 4311 12/09

OO Design Identify or define collections of data and operations on the data Define classes Determine how classes interact

Objects Should

Characteristics of a Good Class

Responsibilities responsibilities

Aside: Objects are not just “data and methods” At this point in design, you must consider objects at the conceptual level. An object is something that has responsibilities.

CRC CRC is a design method. Why CRC? Intuitive. Easy to teach.

CRC Process Identify classes. Identify responsibilities. Assign responsibilities to classes. Identify collaborations. Collect responsibilities into contracts. Define protocols for contracts.

CRC Card One class per card Write subclasses on lines below the name List attributes and purpose on back of card Assign responsibilities Concrete Class: Numeric Keypad Superclass: Keypad Subclasses: None Responsibilities Collaborations

Collaboration A collaboration occurs when one class requires the services of another class in order to fulfill its responsibilities. Indicates classes are coupled.

Contracts A contract is a set of related responsibilities. A contract specifies a service provided by one class to other classes

Protocols A protocol contains method name and type method parameters and types preconditions postconditions A protocol is a formalization of a contract

Finding Classes A class is a collection of objects. Objects = “things” Look for nouns in documents such as the requirements (SRS)

Finding Classes: Advice Be careful of nouns outside the system. Does an object need to act on behalf of the user? Model known interfaces to world (user interfaces, interfaces to programs). Categories may become abstract classes, but just model them as classes for now. The interfaces will evolve to more complex things as time goes by. 14

Identifying Responsibilities Responsibilities are doing and knowing This suggests verbs in English Look for verbs in documents Actions that must be performed Modes of maintaining information

Assigning Responsibilities Assign every responsibility to some class Evenly distribute the intelligence and work-load State responsibilities as generally as possible Keep behavior with related information Collect information about 1 thing in 1 place Pp 63-67 Wirfs-Brock 16

Example There is a voting system with several types of voting machines. These include touch screen machines, voice activated machines (for the sight impaired), and a mouse/keyboard machine (prototyping an interface for web-based voting). There are several different ballots for the machines, one for the city, one for the county, and one for the state. A voter approaches the machine, enters the keycode given to her or him by the election clerk, and the system presents the ballots, one at a time. The voter makes selections, and then casts each of the ballots. Once cast, a vote cannot be modified. Purpose is to give a feel for the process: the details come a little later. 17

Example: Nouns system Voting machine Machine Touch Screen Machine Voice Activated Machine Mouse/Keyboard Machine Interface Ballot One Keycode City County State Her/Him Election Clerk Time Voter Selection Each Vote

Example: Classes Likely Questionable Machine keycode selection Ballot Touch Screen Voice Activated Mouse Keyboard Ballot State County City Voter Vote Questionable keycode selection

Example: Responsibilities Machine Knows which ballots are in the election Can present ballots to a voter Can validate a keycode Knows what selections a voter has made Can cast a ballot Vote Knows what ballot is being voted on Knows a voters selection for items on the ballot Ballot Knows the type of item (issue or candidate) Knows the seats and candidates Knows the issues and the choices Printer, Print Server, and Queue are a subsystem 20

Example: Collaborations Machine and Vote are clients of Ballot Machine is a client of Vote

Problem #1 Missing Classes If you can’t easily assign a responsibility, you may be missing a class. Try to reduce complexity Example: grouping elements in a drawing. The element need not know it’s part of a group. The drawing need not know about groups. But a group class can handle the responsibilities. The group class knows about its members and propagates actions to them.

Problem #2 Arbitrary Assignment If you don’t know what class to assign a responsibility to, consider What are the possibilities (what classes can you assign to)? What are the implications? Which is most obvious? Which is most efficient?

Two Approaches on Distributing Intelligence

Assigning Responsibilities-1 Heuristic: Evenly distribute intelligence Intelligence is what the system knows, actions that it can perform, and impact it has on other systems and users with which it interacts A class gets intelligence based on how much it knows or can do, and how many other objects it can affect.

Assigning Responsibilities-2 Heuristic: State responsibilities as generally as possible. Can find common responsibilities that can be shared Heuristic: Keep behavior with related information. If information changes, no update messages must be sent between objects The object that needs to know that something has changed will know it.

Assigning Responsibilities-3 Heuristic: Keep information about one thing in one place Do not share responsibility for maintaining specific information!! Minimize duplication

Advice Try to express responsibilities in general terms. You are still exploring. Try to keep all of a class’s responsibilities at the same conceptual level (same level of abstraction).

Walk-through What is happening when the machine is idle? What happens when a card is inserted? What happens when the user chooses “withdrawal” from main menu? What happens when the user presses the cancel key?

Finding abstract classes Re-examine list of candidate classes and group related classes Identify those that share attributes Identify those that share behavior Goal is to identify as many abstract classes as possible