您好,登录后才能下订单哦!
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。