如何设计一个ATM | OOD 面向对象高频面试题及解析
作者 | 文泰来老师
编辑 | Jenny
专栏 | 九章算法
如何设计一个ATM Machine?
这是一道常考的OOD面向对象面试题,属于 Real-life Object Deisgn, 类似面试题型有Vending Machine 等。
Assumption: Input 是卡, output 是现金
Input 有什么限制吗?Assumption: 只能是debit card
output 有什么限制吗?Assumption: 只能是20美元的倍数
Assumption: ATM永远有足够的余额 (Bonus: 这里可以考虑如果不够的话应该怎么处理)
Input 有什么特点?Assumption: 一张卡可能有多个账户 (Bonus: 这个不太容易想到, 没想到也没关系,我们可以先按照一个account来做)
- Debit Card
- ATM Machine
- Account
- Take debit card
- Authorization / Log in
- (Optional - 如果一张卡能有多个account就需要这个) Select account
- Check balance
- Deposite money
- Withdraw money
- Log out
- float balance (Optional - 如果ATM机余额有限制就需要这个)
- Session currentSession ( Tips : 如果一个主体,它的操作<比如check balance / deposite / withdraw>是针对每一个用户的, 那么经常会考虑到加入Session这个Class。实践中如果碰到需要login/logout的主体,经常会用到Session)
- void takeDebitCard (DebitCard card)
- List<Account> login (String passcode)
- void selectAccount (Account account)
- float checkBalance ()
- void depositeMoney (float amount)
- float withDrawMoney (float amount)
- void logOut ()
- DebitCard currentDebitCard
- Account currentAccount
- float balance
- void depositeMoney (float amount)
- withDrawMoney (float amount)
1. 增加各式的Exceptions
2. 对于ATM机,有许多种Design pattern可以适用,其中比较合适的就有我们《OOD面向对象专题》课上讲过的State Design Pattern, 大家可以自己思考有哪些合适的states。
ATM Machine作为一道real life object的题目,做法和我们上课讲过的解法大同小异,其中值得注意的三点分别是对Session的使用;可能出现各式各样的Exception; 以及一张卡对应多个 Account的business logic。
九章算法《OOD 面向对象专题班》,由本文作者文泰来老师主讲
免费试听内容:
- OOD 面试中常见面试题总结、分类
- 如何评判一次OOD面试的表现是好是坏
- 设计模式讲解 Design Pattern - Strategy
- 高频OOD面试题讲解 - 电梯设计
免费试听时间:
美西时间3月18日周日 18:30-20:30
美东时间3月18日周日 21:30-23:30
北京时间3月19日周一 09:30-11:30 a.m
长按二维码报名:
- 回复“简历”,查看简历撰写指南,获取“简历模板”
- 回复“冷冻期”,查看北美各大IT企业冷冻期信息和注意事项
- 回复“Career”, 查看Caireer Fair 攻略 check list
- 回复“薪资”,查看北美各大IT企业New Grades Engineer 薪资水平;
- 回复“项目”,查看7-14天可以搞定的小项目推荐
- 回复“评分”,查看系统设计评分指南
- 回复“behavior”,查看behavior interview指南
- 回复“晋升”,查看Engineer晋升机制
九章算法 | 帮助更多中国人找到好工作
《九章算法班》
2018年秋招定制版本
题库全面大换血
根据2018面试趋势调整
新增小知识点总结
配套课前、课后预习复习资料
正在报名中!
报名登陆官网 www.jiuzhang.com
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。