{C++ 基礎(chǔ)} {C++ 高級} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}
posted on 2006-01-03 14:43 夢在天涯 閱讀(1048) 評論(3) 編輯 收藏 引用 所屬分類: Design pattern
definition Provide an interface for creating families of related or dependent objects without specifying their concrete classes. 回復(fù) 更多評論
提供一個(gè)創(chuàng)建一組相關(guān)或無關(guān)對象的接口,而沒有指定具體的類. 回復(fù) 更多評論
實(shí)際上,有些時(shí)候兩者是結(jié)合使用的。我見過BuilderFactory。在Java的DOM模型中就使用了BuilderFactory。 Java 環(huán)境中,解析文件是一個(gè)三步過程: 1、創(chuàng)建 DocumentBuilderFactory。 DocumentBuilderFactory 對象創(chuàng)建 DocumentBuilder。 2、創(chuàng)建 DocumentBuilder。 DocumentBuilder 執(zhí)行實(shí)際的解析以創(chuàng)建 Document 對象。 3、解析文件以創(chuàng)建 Document 對象。 關(guān)鍵代碼如下: import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; import org.w3c.dom.Document; public class OrderProcessor { public static void main (String args[]) { File docFile = new File("orders.xml"); Document doc = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(docFile); } catch (Exception e) { System.out.print("Problem parsing the file: "+e.getMessage()); } } } 很有創(chuàng)意的! 回復(fù) 更多評論