CSC/ECE 517 Fall 2007/wiki2 5 kq: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
 
(55 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''This Wiki Page is edited by Kunta Tsai and Qinyi Ding'''




Line 16: Line 15:
An example of CRC card is shown in figure 1.
An example of CRC card is shown in figure 1.


==Figure 1==
Figure 1:
 
[[Image:CRCCard.gif]]
[[Image:CRCCard.gif]]


Line 22: Line 22:
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.
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.


A common method to determine what cards should be created is to read a specification for the program being designed and consider if each noun should be a class and if each verb should be a responsibility of the noun or class to which it belongs. Naturally, the existence of a noun or verb does not require a class or responsibility in the program, but it is considered a good starting point.
=Best Page Related to CRC ---- Example of ATM Machine=
[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html 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 [http://en.wikipedia.org/wiki/Automated_teller_machine 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.
*[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#ATM Class ATM]
 
<table width = 60%><tr><td>Boundary/entity objects</td><td>Controller objects</td><td>Entity objects</td></tr>
<tr><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#CardReader Class CardReader]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Session Class Session]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Balances Class Balances]</td></tr>
<tr><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#CashDispenser Class CashDispenser]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Transaction Class Transaction]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Card Class Card]</td></tr>
<tr><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#CustomerConsole Class CustomerConsole]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Withdrawal Class Withdrawal]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Message Class Message]</td></tr>
<tr><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#EnvelopeAcceptor Class EnvelopeAcceptor]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Deposit Class Deposit]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Receipt Class Receipt]</td></tr>
<tr><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Log Class Log]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Transfer Class Transfer]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Status Class Status]</td></tr>
<tr><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#NetworkToBank Class NetworkToBank]</td><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#Inquiry Class Inquiry]</td><td></td></tr>
<tr><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#OperatorPanel Class OperatorPanel]</td><td></td><td></td></tr>
<tr><td>[http://www.math-cs.gordon.edu/local/courses/cs211/ATMExample/CRCCards.html#ReceiptPrinter Class ReceiptPrinter]</td><td></td><td></td></tr>
</table>


=Best Page Related to CRC=
There are many other websites which introduce the concept and examples of CRC card. Please refer to the [http://pg.ece.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2007/wiki2_5_kq#Reference Reference] of this page if you are interested.


=Examples of CRC=
=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.


==Ruby Example==
==An Example Using Java==
Let's take a look at a brief example from our best CRC page.


==Java Example==
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:
 
[[Image:CRCCardReader.JPG]]
 
The UML diagram of the class is:
 
[[Image:CardReader.JPG]]
 
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:
<pre>
/*
* 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;   
}
</pre>


=Teaching Exercises for CRC=
=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==
==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 [http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/crc_b/ 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==
==Exercise for Teaching in a Class==


There is an example of how to use role playing to teach OO design through CRC cards by 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 collaboration of CRC cards.
There is an example of how to use role playing to teach OO design through CRC cards by [http://www.cs.umu.se/~jubo/Papers/CRC_CeTUSS07.pdf 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.
[[Image:Library diagram.JPG]]
 
Each student play a role to discuss with others.
 
[[Image:roles.JPG]]
 
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==
==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:
[[Image:crcCardStudent.jpg]]
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=
=Reference=
* [http://en.wikipedia.org/wiki/Class-Responsibility-Collaboration_card Class Responsibility Collaboration Card]
* [http://en.wikipedia.org/wiki/Class-Responsibility-Collaboration_card Class Responsibility Collaboration Card]
* [http://www.possibility.com/epowiki/Wiki.jsp?page=CrcCards Epowiki about CRC Card]
* [http://www.agilemodeling.com/artifacts/crcModel.htm Class Responsibility Collaborator (CRC) Models]
* [http://www.agilemodeling.com/artifacts/crcModel.htm Class Responsibility Collaborator (CRC) Models]
* [http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/crc_b/ CRC Cards Tutorial]
* [http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/crc_b/ CRC Cards Tutorial]
Line 51: Line 206:
* [http://courses.knox.edu/cs292/ATMExample/index.html An Example of Object-Oriented Design: An ATM Simulation]
* [http://courses.knox.edu/cs292/ATMExample/index.html An Example of Object-Oriented Design: An ATM Simulation]
* [http://www.cs.umu.se/~jubo/Papers/CRC_CeTUSS07.pdf CRC-Cards and Roleplay Diagrams Informal Tools to Teach OO Thinking]
* [http://www.cs.umu.se/~jubo/Papers/CRC_CeTUSS07.pdf CRC-Cards and Roleplay Diagrams Informal Tools to Teach OO Thinking]
* [http://www.softstar-inc.com/Download/Intro%20to%20CRC.pdf Introduction to CRC Cards]
* [http://www.visual-paradigm.com/product/vpuml/demos/requirements/crccard.jsp CRC Card Diagram]
* [http://www.d.umn.edu/~gshute/ood/accounts/home.html CRC Cards for Bank Accounts]
* [http://www.cc.gatech.edu/ectropic/papers/extending_crc_cards_sept02.pdf Extending CRC Cards into a Complete Design Process]
* [http://coweb.cc.gatech.edu/cs2340/5583 How to Make Good CRC Cards and Scenarios]

Latest revision as of 03:17, 30 October 2007


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.

Boundary/entity objectsController objectsEntity objects
Class CardReaderClass SessionClass Balances
Class CashDispenserClass TransactionClass Card
Class CustomerConsoleClass WithdrawalClass Message
Class EnvelopeAcceptorClass DepositClass Receipt
Class LogClass TransferClass Status
Class NetworkToBankClass Inquiry
Class OperatorPanel
Class ReceiptPrinter

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