您好,登錄后才能下訂單哦!
A.創建型模式
抽象工廠(Abstract Factory)
javax.xml.parsers.DocumentBuilderFactory
DocumentBuilderFactory通過FactoryFinder實例化具體的Factory.
使用例子: DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse (new File("xxx.xml"));
javax.xml.transform.TransformerFactory
使用例子: StreamSource source = new StreamSource(...); StreamSource stylesource = new StreamSource(...); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(stylesource); StreamResult result = new StreamResult(System.out); transformer.transform(source, result)
javax.xml.xpath.XPathFactory
The structure is almost the same as the previous two.
XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); XPathExpression expr = xpath.compile(XPATH_EXPRESSION_STRING); Object result = expr.evaluate(Object item, QName returnType);
2.生成器模式(Builder)
java.lang.Appendable
java.lang.StringBuilder#append()
java.lang.StringBuffer#append()
這里我們看到狀態的轉換操作都會返回原來的類型的對象,這樣就可以構建生成鏈。
java.nio.ByteBuffer#put()
(CharBuffer
, ShortBuffer
, IntBuffer
, LongBuffer
, FloatBuffer
還有 DoubleBuffer
)
參見上例。
3.工廠方法(Factory method)
java.util.Calendar#getInstance()
工廠方法的構造方法就在所要生成的類型上。 這個抽象工廠有很大不同。
其它的可參見:
java.util.ResourceBundle#getBundle()
java.text.NumberFormat#getInstance()
java.nio.charset.Charset#forName()
java.net.URLStreamHandlerFactory#createURLStreamHandler(String)
java.lang.Object#clone()
5.單例模式(Singleton)
java.lang.Runtime#getRuntime()
java.awt.Desktop#getDesktop()
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。