1
lldong 2011-12-06 22:55:27 +08:00
这算作弊吗?
|
2
Rice 2011-12-06 23:13:20 +08:00
这个……
|
3
Rice 2011-12-06 23:13:31 +08:00
怎么做啊?
|
4
yesmeck 2011-12-06 23:14:01 +08:00
为什么我想到了动物世界。。。
|
5
Mutoo OP @lldong 这个主题只是用于讨论。我已经开始在做了,我尝试写三只小猪。
ThreeLittePigs类 实现 故事书(Story)类 接口模式+1 旁白(Aside) 单例模式+1 实例化猪妈妈与三只小猪(Mother Pig/1st,2nd,3rd Pig)(IObservable),然后讲话的时候传递给旁白(IObserver),旁白再输出转述 观察者模式+1 ... |
6
Mutoo OP @yesmeck hah,差不多,我想到三只小猪……
Aside: Hi! I am the Aside. Mother Pig: Hi! I am the Mother Pig First Little Pig: Hi! I am the First Little Pig Second Little Pig: Hi! I am the Second Little Pig Third Little Pig: Hi! I am the Third Little Pig ========== Three Little Pigs Author: Unknown ========== Aside: There are three little pigs. Aside: They live in a small house with their their mother. "This house is too small. The three of you must leave home. You must build your own homes," says the Mother Pig. |
7
eric_zyh 2011-12-07 11:22:20 +08:00
女娲造人,很面向对象的。。
以前看过一本 《java与模式》 。 里面扯些老子的东西来将面向对象。 可以参考一下。 |
8
reus 2011-12-08 13:04:21 +08:00
既然是敏捷老师布置的,那当然得用些迭代渐进之类的方法吧
第一版就直接用story.tell(),这样直接可以满足五个要求里的四个了~ 第二版加上单例模式啊,Story.getSingleton().tell() 第三版加上代理模式,StoryTeller.getSingleton().tell(Story.getSingleton()) 第四版加上Adapter,我们没有StoryTeller只有Singer,怎么办呢 SingerStoryTellingAdapter<Singer>().tell(Story.getSingleton()) 第五版,getter/setter貌似也是个设计模式是吧 SingerStoryTellingAdapter<Singer>() .tell(Story.getSingleton().setText(story_text).getText()) 第六版加上Factory模式啊 StoryTellerFactory<SingerStoryTellingAdapter<Singer>>() .tell(Story.getSingleton().setText(story_text).getText()) 第七版,一个Factory不够啊,怎么也得上Abstract Factory吧 abstract class TellerFactory {...} abstract class StoryTellerFactory extends TellFactory {...} class SimpleStoryTellerFactory extends StoryTellerFactory {...} SimpleStoryTellerFactory<SingerStoryTellingAdapter<Singer>>() .tell(Story.getSingleton().setText(story_text).getText()) 第八版,来个Chain of Responsibility abstract class TellerFactory {...} abstract class StoryTellerFactory extends TellFactory {...} class SimpleStoryTellerFactory extends StoryTellerFactory {...} StoryTellingRequestHandler() .setSuccessor(StoryTellingRequestConcreteHandler() .setSuccessor( SimpleStoryTellerFactory<SingerStoryTellingAdapter<Singer>() ) ) .handleRequest(RequestType.TELL, Story.getSingleton().setText(story_text).getText()) 第九版,Builder和Prototype都用上了吧 story_text = StoryTextPrototypeBuilder().clone("Once upon a time...") abstract class TellerFactory {...} abstract class StoryTellerFactory extends TellFactory {...} class SimpleStoryTellerFactory extends StoryTellerFactory {...} StoryTellingRequestHandler() .setSuccessor(StoryTellingRequestConcreteHandler() .setSuccessor( SimpleStoryTellerFactory<SingerStoryTellingAdapter<Singer>() ) ) .handleRequest(RequestType.TELL, Story.getSingleton().setText(story_text).getText()) 第十版,Decorate一下,让字符串对象可以直接当作故事来讲 abstract class TellerFactory {...} abstract class StoryTellerFactory extends TellFactory {...} class SimpleStoryTellerFactory extends StoryTellerFactory {...} void String::tellAsStory() { story_text = StoryTextPrototypeBuilder().clone(this) StoryTellingRequestHandler() .setSuccessor(StoryTellingRequestConcreteHandler() .setSuccessor( SimpleStoryTellerFactory<SingerStoryTellingAdapter<Singer>() ) ) .handleRequest(RequestType.TELL, Story.getSingleton().setText(story_text).getText()) } 然后我们就可以这样用了: "Once upon a time...".tellAsStory() …………………………好吧叔叔不行了………………………… |
9
Air_Mu 2011-12-08 13:17:32 +08:00
我想起了当时那个用ML做比喻生动的描述面向对象思想的故事....
|