CSE Roadmap

Core tier · about 2 hours · 7 parts

Part 4 of 7 · 1 min read

Nouns and verbs

Nouns suggest classes, verbs suggest methods.

A simple first pass: read the requirements and underline the nouns and the verbs.

Nouns in the list above: room, id, capacity, floor, user, booking, time slot, day, block. Verbs: book, cancel, search, free.

Then sort the nouns:

Noun What it is
Room Entity: has identity and lives on, with its own data
User Entity
Booking Entity: links a user, a room and a slot
Time slot Value: no identity, defined by its start and end
Capacity, floor, id Attributes of a room
Booking status Enum: a small fixed set (confirmed, cancelled)

An entity is a thing that is tracked over time and told apart by an id. Two rooms with the same capacity are still two rooms. A value object is told apart by what it holds: two slots from 10:00 to 11:00 are the same slot. This split matters later, because values are best made immutable (Level 5).

The verbs suggest methods and who owns them. "Book" needs to see all bookings of a room to check overlaps, so it belongs to a class that holds them, such as a BookingService, not to the Room alone.

Entity and value object

An entity has an identity that stays the same while its data changes. A value object has no identity and is defined only by its data.

Example: a Booking with id B7 stays B7 when it is cancelled (entity). A TimeSlot from 600 to 660 is equal to any other slot from 600 to 660 (value).

Check yourself: 1. Is "capacity" an entity or an attribute? 2. Why is a time slot a value object? 3. Why does "book" not belong to Room alone?