CSC/ECE 517 Fall 2007/wiki2 5 kq
Topic
CRC cards. Hundreds of Web pages cover CRC cards. Which explain them best? Which explain them in the context of specific languages, e.g., Ruby and Java? Which exercises can be used to teach them best, (i) interactively over the Web, (ii) to a class of students, via in-class exercises, (iii) for self-study?
Definition
A Class Responsibility Collaborator (CRC) model (Beck & Cunningham 1989; Wilkinson 1995; Ambler 1995) is a collection of standard index cards that are used when first determining which classes are needed and how they will interact. A CRC card always contain these sections:
- The class name: represents a collection of similar objects
- Its Super and Sub classes (if applicable)
- The responsibilities of the class: represents something a class knows or does
- The collaborator: The names of other classes with which the class will collaborate to fulfill its responsibilities.
- Author
An example of CRC card is shown in figure 1.
Figure 1:
Advantages of CRC Card
Using a small card keeps the complexity of the design at a minimum. It focuses the designer on the essentials of the class and prevents him from getting into its details and inner workings at a time when such detail is probably counter-productive. It also forces the designer to refrain from giving the class too many responsibilities. Because the cards are portable, they can easily be laid out on a table and re-arranged while discussing a design with other people.
Best Page Related to CRC ---- Example of ATM Machine
CRC Cards for ATM Example is a very good page for a CRC card instantiation. We have browsed through hundreds of websites regarding to CRC card, and this page offers a clearest and most complete example using CRC card and Java implementation.
The example the page provides is how to design an ATM machine. It is absolutely not an easy task since an ATM machine has to interact with the bank and the user, and a transaction is also related to reading card and printing receipt. Moreover, the login system is essential to ensure security. In order to deal with the relationship of so many distinct classes of objects, we need the help of CRC card.
The description on the CRC card of each class makes it clear of the responsibility and collaborate class of the specific class, and facilitate the designer to design interfaces more easily.
Below is a complete list of the class used in an ATM machine design. You can click the link to access to the corresponding CRC card.
There are many other websites which introduce the concept and examples of CRC card. Please refer to the Reference of this page if you are interested.
Examples of CRC
Since CRC card is a kind of conceptual description of classes, it uses more natual language than programming language like Java and Ruby. There are few websites which introduce the implementation of CRC card using Java, and fewer using Ruby.
An Example Using Java
Let's take a look at a brief example from our best CRC page.
A card reader is important to an ATM machine. The card reader is the interface to connect ATM and the card. It should tell ATM when a card is inserted, and should be able to read the information in the card. To eject card and retain card are also key functions of a card reader. Therefore, the CRC card of a card reader could look like:
The UML diagram of the class is:
Hence the card reader class should have:
- Variables:
atm: The ATM to which this card reader belongs
- Constructor:
CardReader(ATM): Constructor
- Methods:
ejectCard() : Eject the card that is currently inside the reader. readCard() : Read a card that has been partially inserted into the reader retainCard(): Retain the card that is currently inside the reader for action by the bank.
From the design above, we can easily code the class as:
/* * ATM Example system - file CardReader.java * * copyright (c) 2001 - Russell C. Bjork * */ package atm.physical; import atm.ATM; import banking.Card; import simulation.Simulation; /** Manager for the ATM's card reader. In a real ATM, this would * manage a physical device; in this simulation, it uses classes * in package simulation to simulate the device. */ public class CardReader { /** Constructor * * @param atm the ATM that owns this card reader */ public CardReader(ATM atm) { this.atm = atm; } // In a real ATM, code would be needed to sense insertion of a card into the // slot and notify the ATM - simulated in this case by a button in the GUI /** Read a card that has been partially inserted into the reader * * @return Card object representing information on the card if read * successfully, null if not read successfully */ public Card readCard() { return Simulation.getInstance().readCard(); } /** Eject the card that is currently inside the reader. */ public void ejectCard() { Simulation.getInstance().ejectCard(); } /** Retain the card that is currently inside the reader for action by the * bank. */ public void retainCard() { Simulation.getInstance().retainCard(); } /** The ATM to which this card reader belongs */ private ATM atm; }
Teaching Exercises for CRC
We read many webpages and we selected the ones below as the most suitable examples for different teaching purposes.
Exercise for Teaching Interactively over the Web
Of course the ATM machine example mentioned above is a very good case to study and to teach interactively over the web, since the content is detailed and each class in it is a good exercise to practice using CRC card. Besides the ATM website, another website Object Oriented Analysis and Design using CRC Cards is also very instructive and worth reading.
This website is an online tutorial for how to use CRC card. The tutorial contains two stages: CRC card for analysis and CRC card for design. In the analysis stage there are two activities. The first one is to design an operation system for a technical library for an R&D organization. The author provides a list of possible classes for readers to choose and analyze. The second activity is to stabilize the system by consider more possible flaws of the system. The author summarize the strength of CRC card for analysis are:
- Common Project Vocabulary
- Spread Domain Knowledge
- Making the Paradigm Shift
- Live Prototyping
- Identifying Holes in Requirements
In the design stage the author lists some major elements for CRC design and some additional information to be added to cards in this stage: subresponsibilities, collaborating responsibilities and the data passed. There is the third activity to redo the scenarios in the analysis stage, with consideration of all design heuristics discussed. The author summarize the strength of CRC card for design are:
- Spreading Objet-Oriented Design Expertise
- Design Reviews
- Framework for Implementation
- Informal Notation
All in all, the material in this tutorial is in detail, and is suitable to be used for teaching interactively over web. The teacher could add more features and more detailed thinkings to the activites and the students could practice based on the tutorial.
Exercise for Teaching in a Class
There is an example of how to use role playing to teach OO design through CRC cards by Jürgen Börstler Umeå University, Sweden. It not only works well at teaching CRC cards in class but also a good activity in class. Divide class into groups. Each member in the group presents an object (a CRC card). They can only think of their role. Their responsibilities and how they collaborate with others. Via this way, students can know how to define each CRC card by naming each role; to list what each role can do is to understand how to list responsibilities; to interact with other roles helps to figure out the collaborator of CRC cards. It takes a small library system as example. There are four roles:
- Book: the information about the book, include title, author, register code...etc.
- Librarian: the role who manage books.
- Borrower: the one borrow books include their contact.
- Date: to record which day the book been borrow and return.
Each student play a role to discuss with others.
To let the activities approach, this paper has some suggestions.
- Carefully distinguish between classes and objects.
- Make scenarios as specif as possible.
- Start with the simplest possible meaningful scenario.
- Initialize the role-play properly.
- Be careful with object names.
Exercise for Self-study
Here is a good web page (http://www.agilemodeling.com/artifacts/crcModel.htm) for CRC cards self-study. It simple describes CRC cards at first and using an easy example to teach the rest. The example has only three main roles, student, seminar and professor. Because it’s an example relate to the student experience so it’s easy to understand. Here's the example of one of the CRC card look like:
How to create CRC model? just follow these steps:
- First, find the classes and how to name the classes.
- Second, find the responsibility.
- Third, define the collaborators to find out how each role interactive with others.
- Forth, move the cards around to more clearly figure out the relation of each class.
and then with the small increment you are able to do more practices to learn more about CRC cards. You can create a single requirement such as user story, business rule, or system use case, instead of the entire collection of requirements for your system.
I think this is an easy example for student to self-study. This the example here is related to student experience. Compare to other examples, some are hard for student to understand and some are too complicated. This one with simple case and short description will help student to learn the general idea of CRC cards.
Reference
- Class Responsibility Collaboration Card
- Epowiki about CRC Card
- Class Responsibility Collaborator (CRC) Models
- CRC Cards Tutorial
- Paper of Beck & Cunningham 1989
- Book of Ambler 1995
- CRC Card
- An Example of Object-Oriented Design: An ATM Simulation
- CRC-Cards and Roleplay Diagrams Informal Tools to Teach OO Thinking
- Introduction to CRC Cards
- CRC Card Diagram
- CRC Cards for Bank Accounts
- Extending CRC Cards into a Complete Design Process
- How to Make Good CRC Cards and Scenarios