Overview of CRC

43
CS 4311 1 Overview of CRC CS 4311 B. Beck and W. Cunningham, A Laboratory for Teaching Object-Oriented Thinking, OOPSLA ’89, October 1-6, 1989. R. Wirfs-Brock, B. Wilkerson and L. Wiener, L., Designing Object-Oriented Software, Prentice Hall, 1990. (Chapters 3 and 4)

description

Overview of CRC. CS 4311 B. Beck and W. Cunningham, A Laboratory for Teaching Object-Oriented Thinking, OOPSLA ’89 , October 1-6, 1989. R. Wirfs-Brock, B. Wilkerson and L. Wiener, L., Designing Object-Oriented Software, Prentice Hall, 1990. (Chapters 3 and 4). Outline. Basics of CRC - PowerPoint PPT Presentation

Transcript of Overview of CRC

Page 1: Overview of CRC

CS 4311 1

Overview of CRC

CS 4311 B. Beck and W. Cunningham, A Laboratory for Teaching Object-Oriented

Thinking, OOPSLA ’89, October 1-6, 1989. R. Wirfs-Brock, B. Wilkerson and L. Wiener, L., Designing Object-Oriented

Software, Prentice Hall, 1990. (Chapters 3 and 4)

Page 2: Overview of CRC

2CS 4311

Outline

Basics of CRCCRC CardsCRC Process

Identifying Objects (Classes) Identifying Responsibilities Assigning Responsibilities

Page 3: Overview of CRC

3CS 4311

CRC Cards

Invented in 1989 by Kent Beck and Ward Cunningham

A simple yet powerful object-oriented (analysis/design) technique

Uses a collection of (standard index) cards that are divided into three sections: Class Responsibility Collaborator

Page 4: Overview of CRC

4CS 4311

Class, Responsibility, and Collaborator A class represents a collection of similar

objects. A responsibility is anything that a class

knows or does. A collaborator is another class that is used

to get information for, or performs actions for the class at hand.

Page 5: Overview of CRC

5CS 4311

Example

Class: Person

Superclass:

Subclasses: Student

Responsibilities CollaborationsKnows nameKnows address AddressBookKnows phone number PhoneBook…

Page 6: Overview of CRC

6CS 4311

More on CRC Cards

3x5 (or 4x6) index cards, post-its, etc. One class per card In addition to CRC, can also write

superclasses and subclasses. On the back, can write a description of

purpose of the class (with its attributes).

Page 7: Overview of CRC

7CS 4311

Why CRC Cards?

Page 8: Overview of CRC

8CS 4311

CRC Approach – The Process Exploratory phase

Find classesDetermine operations and knowledge for

each class (responsibilities)Determine how objects collaborate to

discharge responsibilities Analysis phase

Collect into subsystems

Page 9: Overview of CRC

9CS 4311

How to Find Objects and Their Responsibilities? Use nouns and verbs in requirements as clues

Noun phrases leads to objects Verb phrases lead to responsibilities

Determine how objects collaborate to fulfill their responsibilities To collaborate, objects will play certain roles

Why is this important? Objects lead to classes Responsibilities lead to operations or methods Collaborations and roles lead to associations

Page 10: Overview of CRC

10CS 4311

Outline

Basics of CRCCRC CardsCRC Process

Identifying Objects (Classes) Identifying Responsibilities Assigning Responsibilities

Page 11: Overview of CRC

11CS 4311

Identifying Objects (Classes)

Start with requirements specification

1. Look for noun phrases. Separate into obvious classes, uncertain

candidates, and nonsense

2. Refine to a list of candidate classes.

Page 12: Overview of CRC

12CS 4311

Guidelines for Refining Candidate Classes Model physical objects – e.g., disks, printers,

geophones. Model conceptual objects – e.g., windows, files,

shots, picks. Choose one word for one concept – what does it

mean within the domain? Be wary of adjectives – does it really signal a

separate class?

Page 13: Overview of CRC

13CS 4311

Guidelines for Refining (Cont.)

Be wary of missing or misleading subjects – rephrase in active voice.

Model categories of classes – delay modeling of inheritance.

Model interfaces to the system – e.g., user interface, program interface.

Model attribute values, not attributes – e.g., customer vs. customer address.

Page 14: Overview of CRC

14CS 4311

Example: Mail-Order Software

Twice a year the company publishes a catalog of products, which is mailed to customers and other interested people.

Customers purchase products by submitting a list of products with payment to the company. The company fills the order and ships the products to the customer’s address.

The order processing software will track the order from the time it is received until the product is shipped.

The company will provide quick service. They should be able to ship a customer’s order by the fastest, most efficient means possible.

Imagine that you are developing order-processing software for a mail-order company, a reseller of products purchased from various suppliers.

Page 15: Overview of CRC

15CS 4311

Example: Mail-Order Software

Twice a year the company publishes a catalog of products, which is mailed to customers and other interested people.

Customers purchase products by submitting a list of products with payment to the company. The company fills the order and ships the products to the customer’s address.

The order processing software will track the order from the time it is received until the product is shipped.

The company will provide quick service. They should be able to ship a customer’s order by the fastest, most efficient means possible.

Imagine that you are developing order-processing software for a mail-order company, a reseller of products purchased from various suppliers.

Page 16: Overview of CRC

16CS 4311

Candidate Classes

Nouns and Synonyms

softwaremail-order company, company, resellerproductssupplierscatalog of productscustomers, interested peoplelist of products, order, customer’s orderpaymentcustomer’s addresstime it is receivedtime products is shippedquick service

Candidate Class Name

Page 17: Overview of CRC

17CS 4311

Candidate Classes (Cont.)

Expect the list to evolve as design proceedsRecord why you decided to include or reject

candidatesCandidate class list follows configuration

management and version control

Page 18: Overview of CRC

18CS 4311

A Good Class …

Has a clear and unambiguous name Has a name that is recognizable by

domain experts Begins with an uppercase letter and is a

singular noun Has responsibilities May actively participates in system

Page 19: Overview of CRC

19CS 4311

Outline

Basics of CRCCRC CardsCRC Process

Identifying Objects (Classes) Identifying Responsibilities Assigning Responsibilities

Page 20: Overview of CRC

20CS 4311

What Are Responsibilities?

The public services that an object may provide to other objects: The knowledge an object maintains and provides The actions it can perform

That is, Convey a sense of purpose of an object and its place

in the system Record services that a class provides to fulfill roles

within the system Record knowledge (maintenance) and manipulation of

information in the system

Page 21: Overview of CRC

21CS 4311

Knowledge and Action

Knowing responsibilities Knowing about private encapsulated data Knowing about related objects Knowing about things it can derive or calculate

Doing responsibilities Doing something itself, such as creating an object or

doing a calculation Initiating action in other objects Controlling and coordinating activities of other objects

Page 22: Overview of CRC

22CS 4311

Identifying ResponsibilitiesUse mixtures of: Verb phrase identification. Similar to noun phrase

identification, except verb phrases are candidate responsibilities.

Scenarios and role play. Perform scenario walk-through of the system where different persons “play” the classes, thinking aloud about how they will delegate to other objects.

Class enumeration. Enumerate all candidate classes and come up with an initial set of responsibilities.

Class relationship examination. Examine all classes and their relationships to compare how they fulfill responsibilities.

Page 23: Overview of CRC

23CS 4311

Example of Verb Phrase Identification

Twice a year the company publishes a catalog of products, which is mailed to customers and other interested people.

Customers purchase products by submitting a list of products with payment to the company. The company fills the order and ships the products to the customer’s address.

The order processing software will track the order from the time it is received until the product is shipped.

The company will provide quick service. They should be able to ship a customer’s order by the fastest, most efficient means possible.

Imagine that you are developing order-processing software for a mail-order company, a reseller of products purchased from various suppliers.

Page 24: Overview of CRC

24CS 4311

Example of Verb Phrase Identification

Twice a year the company publishes a catalog of products, which is mailed to customers and other interested people.

Customers purchase products by submitting a list of products with payment to the company. The company fills the order and ships the products to the customer’s address.

The order processing software will track the order from the time it is received until the product is shipped.

The company will provide quick service. They should be able to ship a customer’s order by the fastest, most efficient means possible.

Imagine that you are developing order-processing software for a mail-order company, a reseller of products purchased from various suppliers.

Page 25: Overview of CRC

25CS 4311

Candidate Responsibilities

Verbs and Synonyms

Publishes a catalogIs mailed to customersPurchases products; submittingFills the orderShips the products; is shippedTrack the orderIs receivedProvides quick service

Candidate Responsibility

Page 26: Overview of CRC

26CS 4311

Group Exercise

1. Based on the requirement specification of the Weather Monitoring System, identify classes by dividing them into the following three categories: Obvious Discarded Unsure

2. Repeat the exercise for candidate responsibilities.

Page 27: Overview of CRC

27CS 4311

Examining Class Relationships

To identify more responsibilities Types of relations:

Is-kind-of: super and subclasses Is-analogous-to: subclasses of same

superclass? Is-part-of: not inheritance

Page 28: Overview of CRC

28CS 4311

Is-kind-of Relationship

Often indicates superclass and subclass Try to identify common attributes or

actions

Page 29: Overview of CRC

29CS 4311

Is-analogous-to Relationship

May indicate superclass and subclass. Look for common or similar

responsibilities.

Page 30: Overview of CRC

30CS 4311

Is-part-of Relationship

Not superclass and subclass, i.e., the whole need not act like the parts.

Need to be careful about assigning responsibilities.

Object composed of other objects need to know about its parts.

Page 31: Overview of CRC

31CS 4311

Outline

Basics of CRCCRC CardsCRC Process

Identifying Objects (Classes) Identifying Responsibilities Assigning Responsibilities

Page 32: Overview of CRC

32CS 4311

Assigning Responsibilities

Heuristics H1: Distribute intelligence. H2: State responsibilities as generally as possible. H3: Keep behavior with related information. H4: Keep information about one thing in one place. H5: Share responsibilities.

Page 33: Overview of CRC

33CS 4311

Heuristics

H1: Distribute intelligence.

What’s 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; it often amounts to the number of responsibilities assigned for the class.

Why distribute? To make responsibilities smart.

Page 34: Overview of CRC

34CS 4311

Centralized vs. Distributed Intelligence Centralized control (extreme)

One object would know as much as possible about the system, including flow of control.

All other objects would be devoid of intelligence. Disadvantages: makes modification difficult; less

behavior an object has, more unintelligent classes are needed to implement same system.

Page 35: Overview of CRC

35CS 4311

Centralized Control

logic beginsand ends here

objects holdinformation

Page 36: Overview of CRC

36CS 4311

Centralized vs. Distributed (Cont.)

Distributed intelligenceEach object needs to know relatively fewer

thingsProduces a more flexible system Ensure that responsibilities are written at

the same level of detail

Page 37: Overview of CRC

37CS 4311

Distributed Control

logic beginshere logic

ends here

no one object knowsor does much

Page 38: Overview of CRC

38CS 4311

Delegated Control

logic beginshere logic

ends here

coordinatorsmanage each step objects knows

and do a substep

Page 39: Overview of CRC

39CS 4311

Heuristics (Cont.)

H2: State responsibilities as generally as possible.

To find common responsibilities that can be shared.

To make responsibilities reusable.

Page 40: Overview of CRC

40CS 4311

Heuristics (Cont.)

H3: 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.

In sum, this makes responsibilities efficient.

Page 41: Overview of CRC

41CS 4311

Heuristics (Cont.)

H4: Keep information about one thing in one place.

Distribution of information often leads to a duplication, and thus inconsistency.

In sum, make responsibilities safe.

Page 42: Overview of CRC

42CS 4311

Heuristics (Cont.)

H5: Share responsibilities.

A certain responsibility or a compound responsibility can often be best divided or shared among a few closely related objects.

In sum, this make responsibilities simple.

Page 43: Overview of CRC

43CS 4311

Example: Mail-Order System

Class Responsibility

Product Create a catalogSupplier Mail a catalogCatalog Process an order Customer Ship a productOrder Track an orderPayment

? Company? Address ?: Receive an order