-
Notifications
You must be signed in to change notification settings - Fork 66
Description
Chapter 14 > Code > ReservationManager (p291)
Implementation choice: We chose a Set to store Reservation objects because its unique
entry enforcement prevents duplicate bookings, aligning with the need to manage
reservations accurately. An alternative could use a List, which allows simpler iteration but risks
duplicates unless additional checks are added, or a Map with time-based keys, which could
speed up lookups but complicate removal by requiring keys that combine multiple fields,
like time, party size, and name, less suited for the system’s focus on reservation uniqueness.
List
Regarding the explanation about List and Map, can you clarify what the above sentences mean?
My understanding is that iterating over a list or a set is the same:
// iterate over a set
for (var e : set) {
...
}
// iterate over a list
for (var e : list) {
...
}I am not quite sure what the clause "a List, which allows simpler iteration" means.
Map
The explanation about using Map is even more confusing. It states that a map with type-based keys could speed up lookups, but then insists that it requires combined keys with multiple fields, which doesn't look make sense. Can you clarify the explanation?