JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Software Design » GoF  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Factory Method 與 Abstract Factory 有什麼分別?
king_84





發文: 4
積分: 0
於 2005-03-27 01:15 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請教各位高手:
1. Factory Method 與 Abstract Factory 有什麼分別?
2. 什麼情況用Factory Method, 什麼情況用Abstract Factory?


reply to postreply to post
作者 Re:Factory Method 與 Abstract Factory 有什麼分別? [Re:king_84]
alien

小弟劣作一幅



發文: 772
積分: 6
於 2005-03-27 02:09 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
大家著眼的東西不同.

首先, Factory method 其實不在 GoF 所列的 pattern 之內.
Factory Method 的重點是, 經由某 method 來 instantiate object instance, 而非由使用者直接自己 instantiate concrete object.

Abstract Factory 的重點則是, 假設你有一系列的東西要 instantiate, 但你有機會需要在不同的情況下, instantiate 此系列東西的不同的 implementation (或者說, 一種 Concrete 的 Product 系列), 那麼你就可以靠不同的 abstract factory implementation (i.e. Concrete Factory), 每個 Concrete Factory 負責 "製造" 一種 Concrete Product 系列.

既然大家解決的東西不同, 就看你要解決的問題是那一種而套用該 pattern 了


reply to postreply to post

public class Alien {
public boolean isNewbie() {
return true;
}
public String toString() {
return "請大家多多指教";
}
}
作者 Re:Factory Method 與 Abstract Factory 有什麼分別? [Re:alien]
try





發文: 128
積分: 6
於 2005-03-27 10:04 user profilesend a private message to usersend email to tryreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
alien wrote:
首先, Factory method 其實不在 GoF 所列的 pattern 之內.
Factory Method 的重點是, 經由某 method 來 instantiate object instance, 而非由使用者直接自己 instantiate concrete object.


Factory Method(107)應該也是GoF的Pattern哦

我猜你說的是Simple Factory吧?

-try


reply to postreply to post
個人網站 - http://cfliao.net/
作者 Re:Factory Method 與 Abstract Factory 有什麼分別? [Re:king_84]
caterpillar

良葛格

版主

發文: 2613
積分: 70
於 2005-03-27 13:32 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Abstract Factory強調的是一組物件資訊的隱藏性,您可以在不瞭解Factory實例的行為細節下,只要改變Factory的實例,就可以改變整組物件的外觀或行為。。。例如:
1
2
3
4
5
6
7
 CustomDialog windowsDialog = 
      new CustomDialog(new WindowsWidgetFactory());
 windowsDialog.showDialog();
                
 CustomDialog macDialog = 
      new CustomDialog(new MacWidgetFactory());
 macDialog.showDialog();


Factory Method則強調的是先實現行為流程,而將具體行為實現推遲至子物件,例如您可以這麼實現一個編輯器,而不用管編輯器的文件物件是如何實現:
1
2
3
4
5
 public class RTFEditor extends AbstractEditor { 
    public IDocument createDocument() { 
        return new RTFDocument(); 
    } 
 }


這是從應用上看兩個模式的差別,詳細的說明可以參考:
http://openhome.cc/Gossip/DesignPattern/AbstractFactory.htm
http://openhome.cc/Gossip/DesignPattern/FactoryMethod.htm


caterpillar edited on 2013-04-06 17:04
reply to postreply to post
良葛格學習筆記
作者 Re:Factory Method 與 Abstract Factory 有什麼分別? [Re:try]
alien

小弟劣作一幅



發文: 772
積分: 6
於 2005-03-27 18:55 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
try wrote:
Factory Method(107)應該也是GoF的Pattern哦

我猜你說的是Simple Factory吧?

-try

Bingo! 你猜對了... 一時神志不清.... Tongue
大家抱歉, 就忘了我那句說話吧... Tongue


reply to postreply to post

public class Alien {
public boolean isNewbie() {
return true;
}
public String toString() {
return "請大家多多指教";
}
}
作者 Re:Factory Method 與 Abstract Factory 有什麼分別? [Re:king_84]
king_84





發文: 4
積分: 0
於 2005-03-28 01:12 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝各位高手的指點

reply to postreply to post
» JWorld@TW »  Software Design » GoF

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8