CRC Cards example
CRC (Class Responsibility Collaborator) cards are a simple way to break down the functionality of an application to reason about what the basic entities are (class), what they do (responsibility), and which other entities they need to communicate with (collaborator).
In addition to the explanation on Wikipedia, I also recommend the explanation provided by www.agilemodeling.com, as well as the HotDraw example.
Every card should be a standard index card, with the name of the class on the top, and the rest of the card split into responsibilities on the left and collaborators on the right.
Example: Adding user rating to FilmExplorer
To provide you with an example, imagine that we were going to add individualized movie ratings to FilmExplorer. In other words, instead of the current rating system where any user can change the rating on any movie, we will individualize the ratings to be per user. Conceptually the user could then see their rating, as well as the aggregate of the ratings made by others as well.
The Movie
entity is fairly simple, it just has to “know” some things. It has no real collaborators. Note that we have removed the rating
property because it is no longer a single rating per movie.
The User
will represent the user of the system. This entity has a few more responsibilities. Users can log in and out of the system and rate movies. In order to support this, the User
needs to collaborate with an entity that represents those ratings, and an entity that will actually check the user’s credentials and provide access.
We will create a new UserRating
entity to represent a single rating by a user of a single movie.
Finally, we have a SessionManager
, which handles authentication and access control.
CRC cards for views
In this example, we just looked at the data entities in the application. CRC cards can also be used to represent the views (React components) of your application once you are ready to start planning the implementation. This is an example of just one entity.