In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what are the classic design patterns in JDK". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Adapter:
Change one interface or class into another.
Java.util.Arrays#asList () javax.swing.JTable (TableModel) java.io.InputStreamReader (InputStream) java.io.OutputStreamWriter (OutputStream) javax.xml.bind.annotation.adapters.XmlAdapter#marshal () javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal ()
Bridge:
Decouple the abstraction from the implementation, so that the interface and implementation can be completely independent.
AWT (provides the abstraction layer to map to the actual operating system)
JDBC
Composite:
Let the user mix individual objects with composite objects.
Javax.swing.JComponent#add (Component) java.awt.Container#add (Component) java.util.Map#putAll (Map) java.util.List#addAll (Collection) java.util.Set#addAll (Collection)
Decorator:
Dynamically add a series of actions to an object without having to generate a large number of inheritance classes because of the differences in these actions. This pattern is almost ubiquitous in JDK, so the following list is typical.
Java.io.BufferedInputStream (InputStream) java.io.DataInputStream (InputStream) java.io.BufferedOutputStream (OutputStream) java.util.zip.ZipOutputStream (OutputStream) java.util.Collections#checked [List | Map | Set | SortedSet | SortedMap] ()
Facade:
Use a simple interface packet to form a set of components, interfaces, abstractions, or subsystems.
Java.lang.Class javax.faces.webapp.FacesServlet
Flyweight:
Store a large number of small objects efficiently.
Java.lang.Integer#valueOf (int) java.lang.Boolean#valueOf (boolean) java.lang.Byte#valueOf (byte) java.lang.Character#valueOf (char)
Proxy:
Replace a complex object with a simple object.
Java.lang.reflect.Proxy
RMI
Creational (create mode)
Abstract factory:
Create a set of associated object instances. This pattern is also quite common in JDK, and there are many framework such as Spring. It is easy to find such an example.
Java.util.Calendar#getInstance () java.util.Arrays#asList () java.util.ResourceBundle#getBundle () java.sql.DriverManager#getConnection () java.sql.Connection#createStatement () java.sql.Statement#executeQuery () java.text.NumberFormat#getInstance () javax.xml.transform.TransformerFactory#newInstance ()
Builder:
It is mainly used to simplify the creation of a complex object. This pattern can also be used to implement a Fluent Interface.
Java.lang.StringBuilder#append () java.lang.StringBuffer#append () java.sql.PreparedStatement javax.swing.GroupLayout.Group#addComponent ()
Factory:
Simply put, an instance of a type is returned as required.
Java.lang.Proxy#newProxyInstance () java.lang.Object#toString () java.lang.Class#newInstance () java.lang.reflect.Array#newInstance () java.lang.reflect.Constructor#newInstance () java.lang.Boolean#valueOf (String) java.lang.Class#forName ()
Prototype:
Create another instance using your own instance. Sometimes it is a complex action to create an instance and then copy the value of an existing instance. Therefore, this complexity can be avoided by using this pattern.
Java.lang.Object#clone () java.lang.Cloneable
Singleton:
Only one instance is allowed. It is recommended to use Emun in Effective Java.
Java.lang.Runtime#getRuntime () java.awt.Toolkit#getDefaultToolkit () java.awt.GraphicsEnvironment#getLocalGraphicsEnvironment () java.awt.Desktop#getDesktop ()
Behavioral (behavior pattern)
Chain of responsibility:
Pass an object on a link until it is processed. All objects in this chain have the same interface (abstract class) but different implementations.
Java.util.logging.Logger#log () javax.servlet.Filter#doFilter ()
Command:
Encapsulate one or more commands into an object.
Java.lang.Runnable javax.swing.Action
Interpreter:
A pattern of a syntax interpreter.
Java.util.Pattern java.text.Normalizer java.text.Format
Iterator:
Provides a consistent way to traverse all the elements in a container sequentially.
Java.util.Iterator java.util.Enumeration
Mediator:
It is used to reduce the dependence of direct communication of the object order. Use an intermediate class to manage the direction of the message.
Java.util.Timer java.util.concurrent.Executor#execute () java.util.concurrent.ExecutorService#submit () java.lang.reflect.Method#invoke ()
Memento:
Take a snapshot of the state of an object. The Date class internally uses a long type to make this snapshot.
Java.util.Date java.io.Serializable
Null Object:
This pattern is used to solve the situation if there are no elements in a Collection.
Java.util.Collections#emptyList () java.util.Collections#emptyMap () java.util.Collections#emptySet ()
Observer:
Allows an object to broadcast its own messages or events to all listening objects.
Java.util.EventListener javax.servlet.http.HttpSessionBindingListener javax.servlet.http.HttpSessionAttributeListener javax.faces.event.PhaseListener
State:
This mode allows you to easily change the behavior of an object according to its own internal state at run time.
Java.util.Iterator javax.faces.lifecycle.LifeCycle#execute ()
Strategy:
Define a set of algorithms and encapsulate them in an object. Then at run time, you can use one of these algorithms flexibly.
Java.util.Comparator#compare () javax.servlet.http.HttpServlet javax.servlet.Filter#doFilter ()
Template method:
Allows subclasses to overload part of the parent class without the need for a complete override.
Java.util.Collections#sort () java.io.InputStream#skip () java.io.InputStream#read () java.util.AbstractList#indexOf ()
Visitor:
An operation that acts on individual objects in an object group. It allows you to define new operations that act on these objects without changing them.
That's all for javax.lang.model.element.Element and javax.lang.model.element.ElementVisitor javax.lang.model.type.TypeMirror and javax.lang.model.type.TypeVisitor 's "what are the Classic Design patterns in JDK"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.