1 回答

TA貢獻1869條經驗 獲得超4個贊
這將是一個非常通用的答案,但我覺得它需要比評論更多的空間和格式。本質上,您不想使用您class Bus
來管理座位,您Bus
應該只用于管理特定時間公交車上發生的情況。例如:
數量/車牌
巴士上的座位(一旦安排)
離開
到達
司機
ETC
為了調度的目的,您希望有一個class Reservation
包含有關特定日期公交車的所有信息的信息,例如:
日期
離開
到達
座位
這意味著使用你的例子:
User 1 - Reservation(today, Bus 1, Seat A1)
Bus 1 = all reservations for today city A to city B
A1 is empty - fill it.
User 2 - Reservation(tomorrow, Bus 1, Seat A1)
Bus 1 = all reservations for tomorrow city A to city B
A1 is empty - fill it.
User 3 - Reservation(tomorrow, Bus 1, Seat A1)
Bus 1 = all reservations for tomorrow city A to city B
A1 is filled - cannot save reservation
您使用巴士查看某個時間點 - 這還應該包括時間、出發和到達,因為巴士 1 座位 A1 在從城市 B 到城市 A 的行程中可用。
這樣,現在有三輛公交車,但是當他們能夠購買第四輛公交車時,所有的改變就是能夠安排第四個出發/到達對,然后將其應用于車隊中的任何公交車。
添加回答
舉報