You are on page 1of 18

CRC Cards

V4.0
October 2015
Ferreiras

Ferreiras CRC Cards, Ejemplo 1 1


Overview of CRC cards

Are used to represent the responsibilities of


classes and the interaction between the classes.

Are created using classes identified from


problem statement, and any other document
which can help us to know the object that will be
participating in the problem solution.

2
Overview of CRC cards
There are two types of responsibilities for
a class:

1. Knowing ( state of your objects )


About data.
About related objects.
This knowledge is usually stored in
instance variables.

3
Overview of CRC cards
There are two types of responsibilities for a
class:
1.
2. Doing ( behavior, methods )
Deriving or calculating something
Knowing which other objects can do
things.
How to coordinate with other object that do
things.
These abilities are usually performed as
methods
4
Overview of CRC cards
Simulating program run:

Sit at a table and simulate the running


of the program as a conversation
between the CRC cards.

Cards send messages to each other.


Objects invoke method on each
other.

5
Overview of CRC cards
Recording class responsibility:
List the responsibilities as succinctly as possible.
An appropriate phrase (eg: know, maintain,
compute, calculate, display, prompt, read,
provide etc) correctly used conveys the meaning of
the responsibility.
A class should not have a large number of
responsibilities.

6
Overview of CRC cards
Recording a class responsibility:
If the responsibilities cannot be fitted into one
card, it is time to re-think the design:
May be you have included too much detail
(may be you an find a phrase that briefly
conveys the meaning of the responsibility)
May be the class is doing too many things
(time to break up the class into several
classes)
May be some of the responsibilities are
already listed for the super class.
7
Overview of CRC cards
Recording a class collaborator:
A class may have all the data (as data
members) needed to fulfill a responsibility; Or,
Knows other classes that have the rest for
fulfill its responsibility. Then those classes
are identified as collaborators.
From a class perspective, the philosophy is
What I know and Who I know to fulfill a
responsibility.

8
Overview of CRC cards
After you have identified all the classes ( attributes
and operations) that are needed so that your little
software do all the work for which it was created:

Pick out the names of the classes that obviously representing an


important functionality.
Write your responsibilities. If it is necessary, the responsibility
may be refined into smaller tasks if possible.
These smaller tasks can be fulfilled by the same object or they
can be fulfilled be interacting with other objects.
If no appropriate class (to fulfill this responsibility) exists, you may
need to make a new class.

9
Overview of CRC cards
Please read carefully:

This activity (writing the CRC cards) is very important for the success
of your software project; Here you will demonstrate that you have
total control of computational solution of the problem.

From here you what you should do is organize the participation of


classes in computational solution created and start writing the source
code that implements them.

A good style to follow in coding is to implement a class and try, and


try to add more classes and so on; A priority of the classes to
implement should be established as the target in each case.

Good luck !!

10
CRC Card, ATM, Simplified Example

General form to be used:

CRC Card
<<ClassName>>
SYSTEM: FAPROUASD
CREATED BY: Corpito Sitio Largo
DATE, mm-dd-aaaa February-15-2013

Responsibilities of the ClassName CollaboratorClass::method()


- Brief list of responsibilities; And / Or The names of other classes which collaborate
- Signature of individual methods ( FF ) with this class helping her to comply its
responsibilities and the method from this.

Ferreiras CRC Cards, Ejemplo 1 11


Example
Considering make some transactions in an ATM
(only for give you a general idea) some thing for
doing are log into the ATM machine, check
balance, withdraw, and so on; The identified
classes could be: CardReader, UserMenu,
BankSystem, Printer, ...; For these classes, the
CRC cards would be as follows:
<<please see on next slides>>

Ferreiras CRC Cards, Ejemplo 1 12


CRC Card
UserMenu
SYSTEM: ATM
CREATED BY: Ferreiras
DATE, mm-dd-aaaa February-15-2013
Responsibilities of the class UserMenu CollaboratorClass::method( ...)
Display main menu
Ask user for PIN
Send PIN to BankSystem for validation BankSystem::method1(...)
Display validation error
Ask BankSystem for balance BankSystem::method2(...)
Print Balance Printer::method(...)
Debit Account BankSystem::method3(...)
Print Receipt Printer::metho4()
Eject card CardReader::method5(...)

Ferreiras CRC Cards, Ejemplo 1 13


CRC Card
BankSystem
SYSTEM: ATM
CREATED BY: Ferreiras
DATE, mm-dd-aaaa: February-15-2013
Responsibilities of class BankSystem CollaboratoClass::method()
validate PIN
Get Balance

Ferreiras CRC Cards, Ejemplo 1 14


CRC Card, ATM, Simplified Example

General form to be used:

CRC Card
CardReader
SYSTEM: ATM
CREATED BY: Ferreiras
DATE, mm-dd-aaaa: February-15-2013

Responsibilities of class CardReader CollaboratorClass::method

Detect card inserted


Tell UserMenu to ask for PIN UserMenu::method6()
Eject card

Ferreiras CRC Cards, Ejemplo 1 15


CRC Card
Printer
SYSTEM: ATM
CREATED BY: Ferreiras
DATE, mm-dd-aaaa: February-15-2013
Responsibilities of class Printer CollaboratorClass::method
Print Balance
Print Receipt

Ferreiras CRC Cards, Ejemplo 1 16


Important
For all your delivery corresponding to
this work product please use the format
of CRC shown by Ferreiras in this PPT.
...

Ferreiras CRC Cards, Ejemplo 1 17


Reference
OO Design with CRC Cards
CHAPTER 9 OO Design with CRC Cards
www.agileskills.org

Ferreiras CRC Cards, Ejemplo 1 18

You might also like