250 likes | 276 Views
Learn about CRC (Class-Responsibility-Collaboration) cards, a technique to bridge structural and behavioral models in object-oriented design. Create CRC cards to identify class responsibilities and collaborators, fostering better design decisions. Explore examples and good practices for using CRC cards effectively.
E N D
IS514 Lecture Week 9 CRC Cards
So far • Behaviour model • Use Case Diagrams • Use Case Descriptions • Structural Model • Class Diagrams • This week • Continue with Behavioural Model • Class Responsibility Collaboration Cards
Background • Created by Tektronix, in Portland, Oregon (1989) • Large users of Smalltalk • Attributed with the development of several key ideas in object technology • Ward Cunningham and Kent Beck • Presented as a technique to help ‘think objects’ • NOT part of UML http://c2.com/doc/oopsla89/paper.html
Responsibilities and Collaborations • Responsibilities • Knowing • Doing • Collaboration • Objects working together to service a request • Object oriented systems are made up of objects working together to provide functionality • CRC cards can help to form a “bridge” from structural model to behavioral model
The essentials of CRC cards • Anthropomorphism • Pretending classes have human characteristics • Extremely simple technique • Rather than use diagrams to develop models use 4 x 6 index cards • Rather than indicate attributes and operations on the cards, they identify responsibilities and collaborators • Two uses: • Examining domain • Based upon use cases and use case descriptions from the domain
CRC Cards • On the index card, record the following information:- • the name of the class, at the top • the responsibilities of the class, on the left-hand side • the collaborators of the class, which help to carry out each responsibility, on the right-hand side of the card • Many templates exist (see Dennis for another)
Example Simple CRC card Quick exercise – What have I missed? What other responsibilities and collaborators are there?
Exercise 1 • Consider a public house. Consider two classes in the public house. Think about the working of a pub and the interactions between • Bar person • Customer • Draw CRC cards for these two classes • This may involve you identifying other classes • This should take about 10 minutes
What have we seen • Identification of “new” classes • Order • Product • Till • Stock • How classes interact to provide functionality • A feel for behavioural aspects of the system • Each of these would also need a CRC card
CRC Card Responsibilities • The responsibilities of the class describe at a high-level the purpose of the class’s existence • They are connected to the operations the class provides, but are more general than that might imply : • e.g. in a library system “Make Payment” is acceptable as a description of a responsibility • there may well be many associated operations
Coupling & Cohesion • A criteria for Good Analysis / Design • Coupling • Degree of Interconnectedness • Number of links & degree of interaction • Cohesion • Contribution to single purpose • Not mutually exclusive
CRC Good Practice • If a class has lots of responsibilities :- • Can describe them more concisely, and, if not • Would be better to split the responsibilities and have two or more classes • Too many responsibilities: • Bad- low cohesion • Too many collaborators: • Bad -high coupling • Using CRC cards should help to identify and fix both these faults in a model
Why use CRC cards • At the start, you may not know which other classes a class has to collaborate with in order to fulfill a responsibility • Using CRC cards facilitate this • If an object of one class collaborates with an object of another class, it does so by using operations of the other • A class has a relationship with each of it’s collaborators • Using CRC cards is helps to establish in which direction associations should be navigable
Class Diagrams – navigable relationships • So far all relationships in class diagrams and use cases have been navigable in two ways • This is not always the case Officer is investigating a crime Crime doesn’t know which officer is investigating it or indeed if it is being investigated!
CRC cards in practice (1 of 2) • One of the main benefits of CRC cards is that they encourage animated discussion among developers • Especially effective when walking through a Use Case to see how the classes are going to implement it (using role play) • We will see an example of this in the seminars • Anthropomorphism • Developers pick cards as each class collaborates in the Use Case • As ideas about responsibilities are formed the cards are annotated
CRC cards in practice (2 of 2) • Stops thinking about classes as dumb data holders and moves thinking towards understanding the higher-level behavior of each class • CRC cards work on ‘object’ communication (not classes) • Can provide a draft class model • Apart from the technical benefits, stimulates • Team discussion and hence team spirit • Technique suitable for highlighting opportunities to refactor the class model • Refactoring is the process of altering the class model of an object-oriented design without altering it’s visible behavior
Exercise 2 – Have another go • Consider a Library. A library has Borrowers, Books Copies of Books and Reservations. Borrowers can borrow copies of books and make reservations. • Draw CRC cards for the library • Hint classes: • Borrower • Book • Copy • Reservation
This weeks reading ESSENTIAL READING Dennis A, Wixom B, and Tegarden D (2005) System Analysis and Design with UML version 2 second edition, Wiley Chapter 7 ( especially 213-215) Further reading Bennett, S., McRobb, S. and Farmer, R. (2002) Object-Oriented Systems Analysis and Design using UML, 2nd Edition, McGraw-Hill Pages 168-176 • http://c2.com/doc/oopsla89/paper.html • http://www.math-cs.gordon.edu/courses/cs211/ATMExample/CRCCards.html
Summary • What CRC cards are • How to use CRC cards