Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Design Pattern & UML  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 有关工厂方法的问题
needd





发贴: 55
积分: 0
于 2006-07-24 17:20 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请问以下几种方式代码实现是否有区别:
(有图片)



作者 Re:有关工厂方法的问题 [Re:needd]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2006-07-26 20:16 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
当然 有区别,一个调用接口,一个调用的是 实现类


"First they ignore u, then they laugh at u, then they fight u, then u will win

Mahatma Gandhi"

作者 Re:有关工厂方法的问题 [Re:jameszhang]
Jcat

熊猫的猫



发贴: 266
积分: 16
于 2006-07-26 20:49 user profilesend a private message to usersend email to Jcatsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Spring teachs us what's interface-oriented programming!


编程,游泳,睡觉--SleepingCat
作者 Re:有关工厂方法的问题 [Re:needd]
cxp108





发贴: 363
积分: 12
于 2006-07-27 08:58 user profilesend a private message to usersend email to cxp108search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
路过,借搂主宝地问个问题。

大家经常把Factory模式和Singleton模式用在同一个类么?



作者 Re:有关工厂方法的问题 [Re:needd]
needd





发贴: 55
积分: 0
于 2006-07-27 16:59 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位,我还是不太明白,调用接口和调用实现类指的是什么,即代码实现事什么
第一个图的代码实现是



作者 Re:有关工厂方法的问题 [Re:needd]
needd





发贴: 55
积分: 0
于 2006-07-27 17:00 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请问第二个图的代码实现是什么,


作者 Re:有关工厂方法的问题 [Re:cxp108]
needd





发贴: 55
积分: 0
于 2006-07-27 17:01 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
顺便问一下那个create表示什么?在为何没在代码中表现出来?

needd edited on 2006-07-27 17:36

作者 Re:有关工厂方法的问题 [Re:cxp108]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2006-07-30 14:50 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
cxp108 wrote:
路过,借搂主宝地问个问题。

大家经常把Factory模式和Singleton模式用在同一个类么?

应该根据需要!



"First they ignore u, then they laugh at u, then they fight u, then u will win

Mahatma Gandhi"

作者 Re:有关工厂方法的问题 [Re:needd]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2006-07-30 14:51 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
needd wrote:
请问第二个图的代码实现是什么,

仔细 研读 java与 模式



"First they ignore u, then they laugh at u, then they fight u, then u will win

Mahatma Gandhi"

作者 Re:有关工厂方法的问题 [Re:needd]
needd





发贴: 55
积分: 0
于 2006-07-30 15:55 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
jameszhang能诉我一下你的联系方式吗,比如说邮件,msn之类的,在论坛上和你联系太慢的,我的qq 是58222042,先还是感谢一下你能有一次的关注这张帖子。

我仔细看了一下设计模式,我觉得你的解释对于这张UML不太对:
(因为这张图本身就有问题Smile
当然 有区别,一个调用接口,一个调用的是 实现类

我想第一个图和第二个图应该代码是一样的,一样是在于两个类图
ArtTracer一样!

如果代码不一样,那末就错在第二附图本身,既简单工厂模式在有多个
产品对象的情况下,UML图应该画成下面这种形式,我想我以前的理解错
误并不在模式的理解错误,而在于UML图的理解错误,你说对吗?


needd edited on 2006-07-30 16:06

作者 Re:有关工厂方法的问题 [Re:needd]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2006-08-01 20:44 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
图 没有 对错 只是 它反映你的表达意图,如果 你认为 两张图一样那肯定不对,你最后贴出 的 图 中 加 了个 实线 箭头 那将 改变 你的 图示意义。与 原来 采用 虚线箭头 代码表示不同,UML 图例 很严格,因为 他可是 两个程序员交流 语言,是 要 在计算机 上实现的!!如果要搞清关系 ,论坛中 有相关的文章,自己艘以下


"First they ignore u, then they laugh at u, then they fight u, then u will win

Mahatma Gandhi"

作者 Re:有关工厂方法的问题 [Re:needd]
Jacob53





发贴: 6
积分: 0
于 2008-02-12 16:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一张图表示工厂方法可以返回一个带有Shape接口的类的实例,不一定是那三种,也可能是别的,比如一个新的类Pentacle,如果带有Shape接口的话,此工厂方法也可以返回此Pentacle类的实例。

第二张图表示此工厂方法只可以返回那三个类(Circle、Square、Triangle)的实例,其他的类就算满足了Shape接口也不能用此工厂方法制作实例。


Jacob53 edited on 2008-02-12 18:02


flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923