Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

JDK Source Code Reading-2-Design pattern-Creative pattern

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

a. Create a model

Abstract Factory (Abstract Factory)

Javax.xml.parsers.DocumentBuilderFactory

DocumentBuilderFactory instantiates the concrete Factory through FactoryFinder.

Examples of use: DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance (); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder (); Document doc = docBuilder.parse (new File ("xxx.xml"))

Javax.xml.transform.TransformerFactory

Use examples: 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)

two。 Generator mode (Builder)

Java.lang.Appendable

Java.lang.StringBuilder#append ()

Java.lang.StringBuffer#append ()

Here we see that state transition operations return objects of the original type, so that the generation chain can be built.

Java.nio.ByteBuffer#put () (CharBuffer, ShortBuffer, IntBuffer, LongBuffer, FloatBuffer and DoubleBuffer)

See the example above.

3. Factory method (Factory method)

Java.util.Calendar#getInstance ()

The constructor of the factory method is on the type to be generated. This abstract factory is very different.

For more information, please see:

Java.util.ResourceBundle#getBundle ()

Java.text.NumberFormat#getInstance ()

Java.nio.charset.Charset#forName ()

Java.net.URLStreamHandlerFactory#createURLStreamHandler (String)

4. Prototype pattern (Prototye)

Java.lang.Object#clone ()

5. Singleton mode (Singleton)

Java.lang.Runtime#getRuntime ()

Java.awt.Desktop#getDesktop ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report