由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Amazon OO Design 经典题的思考
相关主题
推荐两本OOD和Design Pattern的入门电子书design题需要把head first design pattern那本书看完么?
GoF看完了以后感觉面试中OO设计就是扯淡Amazon onsite 的OOD看什么材料比较好
转行码农,需要学通OO D和Design Pattern吗?面试中会遇到的系统设计题 是指 OO design 吗?
OO design 需要画简单的UML Diagram吗?OO Design 到底是指什么呀?
请问oo design的题,回答格式是什么请问OOD的问题应该如何回答 有哪些资料可以参考
关于design pattern两道经典design问题求助
design类咋准备?OOD:设计conference room reservation system
Design Pattern 实际用的很少吧amazon面试题目讨论贴4--design questions
相关话题的讨论汇总
话题: design话题: room话题: pattern话题: oo
进入JobHunting版参与讨论
1 (共1页)
l********n
发帖数: 54
1
最近开始准备OO design questions, 这两天学习了一下design pattern, 用Amazon了
经典的Hotel Reservation OO
Design的问题练习了一下。希望能和版上各位高手交流一下。
(1) 问题1: 这个system应该就那些类
在version 1设计,我定义了如下类Room, SingleRoom, DoubleRoom, SuitRoom,
Hotel, Customer,
Reservation, Date。 因为感觉这个design,主要就是如何设计check different types
of rooms' availability和make
reservation。
(2) 问题2: 这些类的关系应该如何
其实就是"has-a" and "is-a" 的设计,也就是用inheritance或是composition
。根据直觉定了了如下的UML图
以上两步估计大部分人都能得道,不过如何才能打动interviewer呢?怎么才能提高这
个设计呢?
我想可以从两各方面入手:(1)program with interface (不过这个好像是java
programmer的rule) (2)多用
design pattern, 因为design pattern能decouple code,这样就能提高code的
resuability. 在什么情况下,如何使用
design pattern就是门学问了,需要经验阿!
不过对于这个问题,我想了些改进方法。
(3) 问题3:如何create object
用factory method pattern来建造不同的Room object, 虽然目前的design只有三个
Room-based classes,不过随着以
后系统复杂度的增加,可能回有n个Room-based classes。我猜想design的时候考虑日
后扩展的flexibility,应该也是
interviewer喜欢看到的把。
(4) 问题4: 如何hold多个Room-based objects
是用一个list来hold所有的SingleRoom, DoubleRoom, SuitRoom的object,还是用三个
list来hold各自的object? 这个
没有想好,目前就用了一个list, 因为估计总room的数目不会太大,对单个list进行
iterate的效率不会太差。
(5) 问题5: 如何有效的check availability.
假设有一个customer要查询每种room从某天到某天的availability, 那么需要对所有的
Room subclasses都定义一个查
询函数checkAvailabity()。这样的话不是很好的design。因为日后要加其他的查询:
如Room的朝向(如,有没有view
之类的:-)),那又再改interface, 然后对所有的classes添加函数。麻烦!
所以, 我考虑用strategy pattern可以日后extend各种查询。
(6) 问题6: 找到availability, 如何设计reservation
回想一下,make a reservation其实需要多个步骤的,需要填用户信息,需要填信用卡
(如果是pre-pay的话),需要
计算tax, 还可以用discount code的,最后得到total amount。这些步骤都是
sequential的,有一定的次序。所以我们
可以用builder pattern来generate所有这些步骤。
写个code(看下面link),欢迎各位排砖。
http://www.ideone.com/KsDCV
a***c
发帖数: 2443
2
I think you're looking into this too deep and over-thinking it. For
this
kind of interview questions, I don't think the interviewer is looking
for "
the answer", but rather an answer. From there you pretty much just have
to
wing it and think on the fly. There's always something extra you can
add to
your program to account for some special case. For example, you can add
something to account for walk-in customers, pricing information or even
hourly, weekly, or monthly rental. There's just too many possibilities
and
it all boils down to how much you know about the hotel industry, either
beforehand or from what your interviewer tells you. But all of that
is beside the point. Let your interviewer raise the questions and tell
him/
her how you can adapt your program to these requirement changes. Most
of
these additional design requirements don't really add any complexity
to the
problem, it's just tedious coding work. Seriously, for most general
programming interview questions you don't already know the answers to,
OO design is pretty low on the difficulty scale.
l********n
发帖数: 54
3
恩,多谢指点。不过还是想问问面试的时候,遇到这种问题怎样回答才算是OK的design
我想面试官不会只考你会不会写class,会不会用inheritance, virtual function之类
的吧。
不管这类问题再怎么open,总还是有一些考察的侧重点的吧。
j*****u
发帖数: 1133
4
what is your point?
To me, no design is bad, over design is worse.
I tend to prefer design questions over pure algorithms coding for especially
experinced developers during the interview.It is more important to work, in
most of the cases.
It is easy to differentiate the level of candidates.I would not want to hire
who just coding and coding without thinking.
But keep the design simple. Tell the interviewer why you choose to to this
way rather than that way. Tell him what's your trade-off, why there's a
better solution in terms of beaty design but you don't use it.
Let's take an simple example in your solution. Why do you have the abstract
room class and have different rooms inherited from it? It's not because you
want to use factory pattern, but rather you expect it is a "hot spot" that
is very likely to change, i.e. new type of rooms. Facroty pattern is just
helping you to go there. If there will never or unlikely to have new type of
rooms, there's no need to use patterns which adds complexity.
A good design is beautiful and flexible. Keeping it simple, kowning the
limitations, doing refactory all the time, preparing for the predicable
changes but don't do everything upfront.
Patterns help you to think, to communicate and to achieve a flexible design.
But use it when it's really needed.
hope these are helpful...

【在 a***c 的大作中提到】
: I think you're looking into this too deep and over-thinking it. For
: this
: kind of interview questions, I don't think the interviewer is looking
: for "
: the answer", but rather an answer. From there you pretty much just have
: to
: wing it and think on the fly. There's always something extra you can
: add to
: your program to account for some special case. For example, you can add
: something to account for walk-in customers, pricing information or even

s*******t
发帖数: 248
5
Nice explanation!!

especially
in
hire

【在 j*****u 的大作中提到】
: what is your point?
: To me, no design is bad, over design is worse.
: I tend to prefer design questions over pure algorithms coding for especially
: experinced developers during the interview.It is more important to work, in
: most of the cases.
: It is easy to differentiate the level of candidates.I would not want to hire
: who just coding and coding without thinking.
: But keep the design simple. Tell the interviewer why you choose to to this
: way rather than that way. Tell him what's your trade-off, why there's a
: better solution in terms of beaty design but you don't use it.

a***c
发帖数: 2443
6
so do you agree with me or do you not? I'm kind of confused. I think you
just
rephrased the stuff I said.

especially
in
hire

【在 j*****u 的大作中提到】
: what is your point?
: To me, no design is bad, over design is worse.
: I tend to prefer design questions over pure algorithms coding for especially
: experinced developers during the interview.It is more important to work, in
: most of the cases.
: It is easy to differentiate the level of candidates.I would not want to hire
: who just coding and coding without thinking.
: But keep the design simple. Tell the interviewer why you choose to to this
: way rather than that way. Tell him what's your trade-off, why there's a
: better solution in terms of beaty design but you don't use it.

j*****u
发帖数: 1133
7
it seems we were talking about similiar thing in different perspective
I wasn't rephrasing just didn't read yours carefully - sorry
I just read again

【在 a***c 的大作中提到】
: so do you agree with me or do you not? I'm kind of confused. I think you
: just
: rephrased the stuff I said.
:
: especially
: in
: hire

s*****n
发帖数: 5488
8
search online. you will find if this is questioned in phone interview,
basically they just wnat to make sure you know the abc of OOD. very basic.
However, there will be other issues can be discussed besides OOD like the
data structures/algorithm used for example to query : which room is free
during some day to some day, efficiently. It would be nice to use design
patterns. However, I don't see it is obvious for this question.
C*********E
发帖数: 578
9
牛。

【在 s*****n 的大作中提到】
: search online. you will find if this is questioned in phone interview,
: basically they just wnat to make sure you know the abc of OOD. very basic.
: However, there will be other issues can be discussed besides OOD like the
: data structures/algorithm used for example to query : which room is free
: during some day to some day, efficiently. It would be nice to use design
: patterns. However, I don't see it is obvious for this question.

j*********0
发帖数: 5
10
Then what is the ABC of OOD? Thank you.

【在 s*****n 的大作中提到】
: search online. you will find if this is questioned in phone interview,
: basically they just wnat to make sure you know the abc of OOD. very basic.
: However, there will be other issues can be discussed besides OOD like the
: data structures/algorithm used for example to query : which room is free
: during some day to some day, efficiently. It would be nice to use design
: patterns. However, I don't see it is obvious for this question.

a***c
发帖数: 2443
11
I think the trick is to start small, then literally work with your
interviewer. Ask questions whenever you need clarification, assume nothing;
show him your design process rather than your design. Be more proactive, it'
s
better to ask questions than getting hints from him/her because you
overlooked
something. For the hotel reservation problem, having the basic stuff, e.g.
room type, availability, etc is plenty good enough to get the discussion
going, from there, you could start asking questions like how is the system
used, is it run at multiple sites (think concurrency, database)? does it
need
an interface for third party online reservation agencies? maybe yet another
interface for other travel agencies? is commission handled by your system as
well? what information should be made available to these third parties?

design

【在 l********n 的大作中提到】
: 恩,多谢指点。不过还是想问问面试的时候,遇到这种问题怎样回答才算是OK的design
: 我想面试官不会只考你会不会写class,会不会用inheritance, virtual function之类
: 的吧。
: 不管这类问题再怎么open,总还是有一些考察的侧重点的吧。

l********n
发帖数: 54
12
Great! 多谢各位的讨论和idea. 现在有点知道该怎么回答这类问题了
1 (共1页)
进入JobHunting版参与讨论
相关主题
amazon面试题目讨论贴4--design questions请问oo design的题,回答格式是什么
电话及onsite面试的一些小提示关于design pattern
Amazon面经design类咋准备?
OOD amazon questionsDesign Pattern 实际用的很少吧
推荐两本OOD和Design Pattern的入门电子书design题需要把head first design pattern那本书看完么?
GoF看完了以后感觉面试中OO设计就是扯淡Amazon onsite 的OOD看什么材料比较好
转行码农,需要学通OO D和Design Pattern吗?面试中会遇到的系统设计题 是指 OO design 吗?
OO design 需要画简单的UML Diagram吗?OO Design 到底是指什么呀?
相关话题的讨论汇总
话题: design话题: room话题: pattern话题: oo