Structural (Structure Mode)
Adapter:
Converts an interface or class to another one.
• 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:
Abstract and implementation are decoupled, so interfaces and implementations can be completely independent.
• AWT (provides the abstraction layer mapped to the actual operating system)
• JDBC
Composite:
Allows users to mix individual objects and 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, instead of generating a large number of inheritance classes because of these actions. This mode is almost everywhere in JDK, so the following list is just a typical one.
• 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:
A simple interface is used to package a group of parts, interfaces, abstractions, or subsystems.
• Java. Lang. Class
• Javax. Faces. webapp. facesservlet
Flyweight:
Efficiently store a large number of small objects.
• 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 (Creation Mode)
Abstract Factory:
Create a group of associated object instances. This mode is also quite common in JDK, and there are many frameworks such as spring. We can easily find such an instance.
• 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 mode 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, return a type of instance as needed.
• 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:
Use your own instance to create another instance. Sometimes, creating an instance and copying the value of an existing instance is a complex action. Therefore, this mode can avoid such complexity.
• Java. Lang. Object # clone ()
• Java. Lang. cloneable
Singleton:
Only one instance is allowed. We recommend that you use emun.
• Java. Lang. runtime # getruntime ()
• Java. AWT. Toolkit # getdefatooltoolkit ()
• Java. AWT. graphicsenvironment # getlocalgraphicsenvironment ()
• Java. AWT. Desktop # getdesktop ()
Behavioral (behavior mode)
Chain of responsibility:
Transfer an object in a link until it is processed. All objects on 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:
The mode of a syntax interpreter.
• Java. util. Pattern
• Java. Text. normalizer
• Java. Text. Format
Iterator:
Provides a consistent method to traverse all elements in a container in sequence.
• Java. util. iterator
• Java. util. Enumeration
Mediator:
It is used to reduce the dependency of direct communication between object tickets. Use an intermediate class to manage the message direction.
• Java. util. Timer
• Java. util. Concurrent. executor # execute ()
• Java. util. Concurrent. executorservice # submit ()
• Java. Lang. Reflect. method # invoke ()
Memento:
Create a snapshot of the status of an object. The date class uses the long type internally for this snapshot.
• Java. util. Date
• Java. Io. serializable
Null Object:
This mode is used to solve the problem of 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 based on its internal state at runtime.
• Java. util. iterator
• Javax. Faces. lifecycle. lifecycle # execute ()
Strategy:
Defines a set of algorithms and encapsulates them into an object. Then, you can use one of the algorithms flexibly during running.
• Java. util. comparator # Compare ()
• Javax. servlet. http. httpservlet
• Javax. servlet. Filter # dofilter ()
Template Method:
The subclass is allowed to overload some parent classes without completely rewriting.
• Java. util. Collections # Sort ()
• Java. Io. inputstream # Skip ()
• Java. Io. inputstream # Read ()
• Java. util. abstractlist # indexof ()
Visitor:
Operations on objects in an object group. This allows you to define new operations on these objects without changing the objects themselves.
• Javax. Lang. model. element. element and javax. Lang. model. element. elementvisitor
• Javax. Lang. model. type. typemirror and javax. Lang. model. type. typevisitor
(Full text)
From: http://coolshell.cn/articles/3320.html
Reference: http://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns