D0: design summary

设计电梯,停车场, 纸牌 和 动物


再来一个design的题


☆─────────────────────────────────────☆

  HNM ( ) 于 (Sun Jan 10 17:17:33 2010, 美东) 提到:

一个汽车工厂生产各种各样的车,比如卡车,乘客车等等

每辆车有不同特性,比如有的有天窗,有的四个门,有的两个门

现在让你设计一个测试车的程序,比如说,想测试电池,那么所有有电池的车都要被测试;
如果想测试天窗,那么所有有天窗的车都要被测试.

给出class,和主要function.

这个又是什么pattern之类的呢?




※ 来源:·BBS 未名空间站 海外: mitbbs.com 中国: mitbbs.cn·[FROM: 8.12.]



☆─────────────────────────────────────☆

  asuran (少说空话,多做实事) 于 (Sun Jan 10 17:22:27 2010, 美东) 提到:

设计电梯,停车场, 纸牌 和 动物园, 这几个题比较经典, 也可以讨论一下
不过我觉得设计不应该从pattern 入手, 应该先从需求入手,分析client-server 的
接口




☆─────────────────────────────────────☆

  HNM ( ) 于 (Sun Jan 10 17:24:09 2010, 美东) 提到:

是是
牛人,那么20多个pattern,你觉得哪些比较重点? 

【 在 asuran (少说空话,多做实事) 的大作中提到: 】
: 设计电梯,停车场, 纸牌 和 动物园, 这几个题比较经典, 也可以讨论一下
: 不过我觉得设计不应该从pattern 入手, 应该先从需求入手,分析client-server 的
: 接口





☆─────────────────────────────────────☆

  asuran (少说空话,多做实事) 于 (Sun Jan 10 17:38:36 2010, 美东) 提到:

我觉得gowii这方面比较牛,我的一点体会:
创建者模式用的最多的是factory method, singleton
结构模式用的最多的是proxy, adapter, facade
行为模式中observer, command, state, strategy, template method 用的最多
面试我倒不是很清楚
不过我觉得最难的pattern是visitor.
还有一个非常重要的pattern就是 MVC,这个非常经典,要实现出来也是很困难的

另外实现上proxy, adapter 和 decorator 很像。
目的而言template method 和 strategy 很像。

我觉得设计模式的种类划分, 是根据目的划分的, 就是design pattern中每个
pattern章节的第一句话, 如果上手就看实现的话,会很乱。

不过这些都是做项目的体会, 和面试关系不是很大。

【 在 HNM ( ) 的大作中提到: 】
: 是是
: 牛人,那么20多个pattern,你觉得哪些比较重点? 






☆─────────────────────────────────────☆

  HNM ( ) 于 (Sun Jan 10 17:58:46 2010, 美东) 提到:

谢谢.
存了.
你有没有总结过像动物园,电梯停车场这种题?

【 在 asuran (少说空话,多做实事) 的大作中提到: 】
: 我觉得gowii这方面比较牛,我的一点体会:
: 创建者模式用的最多的是factory method, singleton
: 结构模式用的最多的是proxy, adapter, facade
: 行为模式中observer, command, state, strategy, template method 用的最多
: 面试我倒不是很清楚
: 不过我觉得最难的pattern是visitor.
: 还有一个非常重要的pattern就是 MVC,这个非常经典,要实现出来也是很困难的
: 另外实现上proxy, adapter 和 decorator 很像。
: 目的而言template method 和 strategy 很像。
: 我觉得设计模式的种类划分, 是根据目的划分的, 就是design pattern中每个
: ...................




☆─────────────────────────────────────☆

  asuran (silence) 于 (Sun Jan 10 18:05:47 2010, 美东) 提到:

没有。我最近也打算看看类似的问题
一般面试的时候给的requirement都不多, 大都需要自己问, 不能光靠假设来设计。
设计类的问题最好能大家一起讨论

网上copy来的

How would you model a parking lot? 

What to look for? 
Expected answer: A parking lot is (at least conceptually) a container for 
objects of type vehicle - vehicle may be subclassed for different kinds of 
vehicles: trucks, motorcycles, cars, ... - Important concepts: container, 
inheritance! 

Does the candidate jump to conclusions as to what the parking lot is 
supposed to do? 

Does the candidate approach this problem in an object-oriented way or in a 
data-driven or functional way? 

After the first general stab, the candidate should ask for additional 
requirements: what is the parking lot supposed to do, how is it to be used. 
Does the candidate offer possible ways that it might be used (in a fitting 
problem, in a real-time control system, in a billing problem, for instance) 

Comments about implementation issues are generally inappropriate, unless the
specific use of the parking lot has been established! 

Follow-up question: What functionality would be abstracted/encapsulated in 
the parking lot? Expected answer: size or capacity, occupancy, even which 
slots are filled. Anything else depends on the specific usage! 

Advanced follow-up question: where should the responsibility to to park a 
vehicle? ParkingLot.park( Vehicle ) or Vehicle.park( ParkingLot )? Reason 
for choice? Introduce Meilir Page-Jones example: unmilk the cow, or uncow 
the milk? Therefore: Introduce parking mgr (Can the candidate name an 
applicable Pattern? Mediator!) 

Benefits: 
less smart objects: more reusable 
less coupling (otherwise cars need to know about parking lot and vv) 
Single pt of control 
Better conceptual modeling!!!

【 在 HNM ( ) 的大作中提到: 】
: 谢谢.
: 存了.
: 你有没有总结过像动物园,电梯停车场这种题?







☆─────────────────────────────────────☆

  HNM ( ) 于 (Sun Jan 10 18:09:08 2010, 美东) 提到:

这个哪拷的?说的还挺有道理的.

【 在 asuran (silence) 的大作中提到: 】
: 没有。我最近也打算看看类似的问题
: 一般面试的时候给的requirement都不多, 大都需要自己问, 不能光靠假设来设计。
: 设计类的问题最好能大家一起讨论
: 网上copy来的
: How would you model a parking lot? 
: What to look for? 
: Expected answer: A parking lot is (at least conceptually) a container for 
: objects of type vehicle - vehicle may be subclassed for different kinds of 
: vehicles: trucks, motorcycles, cars, ... - Important concepts: container, 
: inheritance! 
: ...................





☆─────────────────────────────────────☆

  asuran (silence) 于 (Sun Jan 10 18:14:22 2010, 美东) 提到:

google来的。。



☆─────────────────────────────────────☆

  krone (krone) 于 (Sun Jan 10 21:30:26 2010, 美东) 提到:

看了设计也是你的强项!
顶!

【 在 asuran (少说空话,多做实事) 的大作中提到: 】
: 我觉得gowii这方面比较牛,我的一点体会:
: 创建者模式用的最多的是factory method, singleton
: 结构模式用的最多的是proxy, adapter, facade
: 行为模式中observer, command, state, strategy, template method 用的最多
: 面试我倒不是很清楚
: 不过我觉得最难的pattern是visitor.
: 还有一个非常重要的pattern就是 MVC,这个非常经典,要实现出来也是很困难的
: 另外实现上proxy, adapter 和 decorator 很像。
: 目的而言template method 和 strategy 很像。
: 我觉得设计模式的种类划分, 是根据目的划分的, 就是design pattern中每个
: ...................





☆─────────────────────────────────────☆

  goWii (wii) 于 (Tue Jan 12 14:58:21 2010, 美东) 提到:

VISITOR的本质实际上是double dispach,实际应用的很少,因为其紧耦合。。。

【 在 asuran (少说空话,多做实事) 的大作中提到: 】
: 我觉得gowii这方面比较牛,我的一点体会:
: 创建者模式用的最多的是factory method, singleton
: 结构模式用的最多的是proxy, adapter, facade
: 行为模式中observer, command, state, strategy, template method 用的最多
: 面试我倒不是很清楚
: 不过我觉得最难的pattern是visitor.
: 还有一个非常重要的pattern就是 MVC,这个非常经典,要实现出来也是很困难的
: 另外实现上proxy, adapter 和 decorator 很像。
: 目的而言template method 和 strategy 很像。
: 我觉得设计模式的种类划分, 是根据目的划分的, 就是design pattern中每个
: ...................






☆─────────────────────────────────────☆

  goWii (wii) 于 (Tue Jan 12 15:02:22 2010, 美东) 提到:

VISITOR
例子WIKI上有
http://en.wikipedia.org/wiki/Visitor_pattern

【 在 HNM ( ) 的大作中提到: 】
: 一个汽车工厂生产各种各样的车,比如卡车,乘客车等等
: 每辆车有不同特性,比如有的有天窗,有的四个门,有的两个门
: 现在让你设计一个测试车的程序,比如说,想测试电池,那么所有有电池的车都要被测
试;
: 如果想测试天窗,那么所有有天窗的车都要被测试.
: 给出class,和主要function.
: 这个又是什么pattern之类的呢?
: ※ 来源:·BBS 未名空间站 海外: mitbbs.com 中国: mitbbs.cn·[FROM: 
8.12.]






☆─────────────────────────────────────☆

  mitbbs59 (bEQi) 于 (Tue Jan 12 15:25:51 2010, 美东) 提到:

我早就想请教了,这些题好多公司都喜欢问了,
不过没看到什么全面的答案,大家是该好好讨论一下

【 在 asuran (少说空话,多做实事) 的大作中提到: 】
: 设计电梯,停车场, 纸牌 和 动物园, 这几个题比较经典, 也可以讨论一下
: 不过我觉得设计不应该从pattern 入手, 应该先从需求入手,分析client-server 的
: 接口






☆─────────────────────────────────────☆

  adamchenya (yadwer) 于 (Tue Jan 12 15:30:37 2010, 美东) 提到:

你真是太强了。你是我见过design最强的。很多partten连听都没听说过。
【 在 asuran (silence) 的大作中提到: 】
: 没有。我最近也打算看看类似的问题
: 一般面试的时候给的requirement都不多, 大都需要自己问, 不能光靠假设来设计。
: 设计类的问题最好能大家一起讨论
: 网上copy来的
: How would you model a parking lot? 
: What to look for? 
: Expected answer: A parking lot is (at least conceptually) a container for 
: objects of type vehicle - vehicle may be subclassed for different kinds of 
: vehicles: trucks, motorcycles, cars, ... - Important concepts: container, 
: inheritance! 
: ...................






☆─────────────────────────────────────☆

  mvcfan (mvcfan) 于 (Thu Feb 11 17:02:45 2010, 美东) 提到:

我来一个汽车design的粗浅解法,大家讨论一下,共同进步。
附件是UML图。下面是Factory中Test方法的C#伪码:

// t should be one of the subclass of class Part
Void Test(Type t)
{
   foreach(var car in Cars)
   {
      foreach(var part in car.Parts)
      {
         if(part is t)
           part.test();
       }
    }

}

以上程序可以用Linq简化。由于手头没有编译器就不做了。



☆─────────────────────────────────────☆

  mvcfan (mvcfan) 于 (Thu Feb 11 17:52:24 2010, 美东) 提到:


【 在 mvcfan (mvcfan) 的大作中提到: 】
: 我来一个汽车design的粗浅解法,大家讨论一下,共同进步。
: 附件是UML图。下面是Factory中Test方法的C#伪码:
: // t should be one of the subclass of class Part
: Void Test(Type t)
: {
:    foreach(var car in Cars)
:    {
:       foreach(var part in car.Parts)
:       {
:          if(part is t)
: ...................






※ 来源:·BBS 未名空间站 海外: mitbbs.com 中国: mitbbs.cn·[FROM: 63.98.]

此主题相关图片如下:

1.jpg
(32128 字节)

此主题相关图片如下:
1.jpg
(32128 字节)

 

posted @ 2013-03-05 17:18  西施豆腐渣  阅读(228)  评论(0编辑  收藏  举报