Lesson 3 | Responsibilities and collaborators |
Objective | Describe the responsibilities and collaborators for the video store example. |
Video Store Example using Responsibilities and Collaborators
The video store example has six classes at the moment:
- Customer,
- Inventory,
- Rental,
- Reservation,
- Title, and
- Video.
Each class has certain responsibilities, such as tracking or recording information or making calculations. We distinguish between a title and a video because there may be several copies of a popular title in stock. Each video may be out or available, for example. Customers query about titles, though: They do not care whether copy 7 is available or not, as long as at least one copy is available.
Here is a summary of the responsibilities of each class:
- Customer: Tracks name, address, and phone number. Records payments and charges and keeps an account balance.
- Inventory: Keeps a list of titles. Finds available videos.
- Rental: Represents a rental transaction. Records duration, calculates charges, marks video as out, processes the return.
- Reservation: Represents a reservation of a title. Records customer and date, marks video as reserved.
- Title:Keeps a list of videos, finds available video. Knows charges for this title.
- Video: Tracks status (out, reserved, available).
You can see in these descriptions that classes collaborate to get things done.
The Rental class marks the video as out (rented), but that information is kept in the Video class, so on that responsibility, Video is a collaborator.
When Inventory finds an available video, it does so by getting the Title class to collaborate. This kind of interaction is vital to any object-oriented application.
Video Store - Quiz
Click the Quiz link below to identify responsibilities and collaborators in the course project.
Video Store - Quiz