步骤
题目后面都可以接上三个字:“管理员”
- NO implementation:
- clarify requirement:问清楚哪些是必须的,哪些可以忽略
- define class (core object):定义哪些class,以及有哪些具体的不同类型
- 角度1:除了题目中问的object(管理员)外,被管理的objects有哪些
- 角度2:这个管理系统中,input和output是什么
- 角度3:常用「收据」的形式,来保存信息(ie:停车票/借书单……)
- define field:每个class有哪些field
- define method, how data flow works:class之间如何交互
- 把自己想象成「管理员」,思考use case(一般从以下3个角度思考)
- 预定
- 服务
- 结算
- inheritance(interface / abstract class)为了好扩展
- 把自己想象成「管理员」,思考use case(一般从以下3个角度思考)
- Implementation:
- implement核心关键methods
- *optimize with design pattern (锦上添花,optional)
停车场
class / field / method:
- class:parking lot:本身作为一个系统,里面直接保存停车位等信息
- field:
- map<location, parkingSpot>
- map<location, parkingTicket>:可以优化提取成一个单独的system
- capcity of each type of parking spot:可以先hardcode,再优化成可扩展的
- method:
- Ticket park(String vehicle):停车 -> 根据车子的类型来分配车位并出票
- user give a vehicle type
- check if there is available parking spot for this type of vehicle
- (optional) *check if there is larger spot available if exact size spot is full
- add
<location, parking spot>
to our local map, and decrease capacity - create a parking ticket and get it back to the user
- Ticket exit(Ticket ticket):离开 -> 释放车位,根据车票计算收费 -> 返回车票作为收据
- read ticket and calculate fee(可能根据车子的类型有不同的收费标准,用strategy pattern)
- relase parking spot, increase capacity
- update ticket and return it back to the user as a receipt
- Ticket park(String vehicle):停车 -> 根据车子的类型来分配车位并出票
- field:
- class:parking spot(abstract class):给各种不同车型的停车位(output)
- field:
- parking location (ie: A3, B4, ...)
- field:
- class:parking ticket
- field:
- parking location
- enter/exit timestamp
- charge fee amount/ratio
- field:
- *class:vehicle(input)
- *class:admin/user class
- *class:payment class:信用卡/现金...