CRC Card
CRC Card
CRC Card
by Charles W. Neville
copyrignt 2000 by Charles W. Neville
0. Introduction.
---------------------------------------------------
| Class Name | Collaborators |
| ----------------------------- | |
| Responsibilities | |
| | |
| | |
| | |
---------------------------------------------------
The "Class Name" section just contains the name of the class.
---------------------------------------------------
| Class Name |
| ----------------------------- |
| Variables |
| |
| |
| Methods |
| |
| |
| |
---------------------------------------------------
You may have noticed that CRC cards don't have much room on
them. They are
rather small 4 by 6 notecards. This enforces a useful rule of
class design: A
class that has more responsibilities than can be listed on a
small note card is
too large, and needs to be divided into smaller classes.
First, let us write out both sides of a CRC card for the
Balloon class.
Front side:
---------------------------------------------------
| Class Name Balloon | Collaborators |
| ----------------------------- | |
| Responsibilities | |
| Maintain size and position | |
| Display itself | |
| Move itself left and right | |
| Shrink and grow itself | |
| ---------------- |
| Remark: Combined view and model |
---------------------------------------------------
Back side:
---------------------------------------------------
| Class Name Balloon |
| ----------------------------- |
| Variables |
| int diameter diameter of balloon |
| int xCoord, yCoord x and y coordinates of |
| balloon |
| Methods |
| public void display(Graphics g) display |
| itself on graphics object g |
| public void left() move left |
| public void right() move right |
| public void grow() grow itself |
| public vod shrink() shrink itself |
| |
---------------------------------------------------
Next, let us write out both sides of a CRC card for the
PlayBalloon class.
Front side:
---------------------------------------------------
| Class Name PlayBalloon | Collaborators |
| ----------------------------- | Balloon |
| Responsibilities | |
| Display Buttons for | |
| user input. | |
| When a button is clicked, | |
| send appropriate messages | |
| to Balloon object. | |
| Repaint screen | |
| Send display message to | |
| Balloon object | |
| ---------------- |
| Remark: Controller |
---------------------------------------------------
Back side:
---------------------------------------------------
| Class Name PlayBalloon |
| ----------------------------- |
| Variables |
| Button grow, shrink, |
| left, right buttons for user input |
| Balloon myBalloon the balloon object |
| |
| Methods |
| public void init() add buttons to Applet |
| panel |
| public void actionPerformed(ActionEvent event) |
| process user button clicks |
| and call repaint() |
| public void paint(Graphics g) send display |
| message to myBalloon object |
| |
---------------------------------------------------