CSE Roadmap

Core tier · about 2 hours · 7 parts

Part 2 of 7 · 1 min read

The class box

Three rows: name, data, actions.

A class box has three rows. The top row holds the name. The middle row holds fields. The bottom row holds methods. A + before a name means public, and a - means private.

+---------------------------+
| Booking                   |
+---------------------------+
| - id: String              |
| - room: Room              |
| - slot: TimeSlot          |
| - status: BookingStatus   |
+---------------------------+
| + cancel()                |
| + isActive(): boolean     |
+---------------------------+

On a whiteboard, drop everything that does not help the answer. Fields that are obvious can be left out. Two or three methods per class are usually enough. Interviewers want to see the design, not a full listing.

Class diagram

A class diagram shows classes as boxes and the links between them as lines, so that the structure of a program is visible at a glance.

Example: a box for Booking joined by a line to a box for Room, labelled "for one room".

Check yourself: 1. What do the three rows of a class box hold? 2. What does a minus sign before a field mean? 3. Why drop obvious fields on a whiteboard?