Practical application of design patterns in JAVA __java

Source: Internet
Author: User
Tags addall
Recently looking at design patterns, find a good blog, explaining the various design patterns in the Java specific application scenarios, Bowen address http://blog.jobbole.com/62314/. Structured mode: Adapter Mode:

Used to transform an interface into another interface. 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 () Bridging mode:

This pattern is decoupled from the implementation of abstract and abstract operations so that abstractions and implementations can be changed independently. AWT (It provides an abstraction layer which maps onto the native OS the windowing.) Jdbc

Combination Mode

Makes the client seem to have the same combination of individual objects and objects. In other words, a type of method also accepts its own type as an argument. 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 Mode:

Dynamically attaching additional functionality to an object, which is also an alternative to subclasses. As you can see, when you create a type, you also pass in the same type of object. It's everywhere in the JDK and you'll find it's everywhere, so this list is just a small part of it. Java.io.BufferedInputStream (InputStream) java.io.DataInputStream (InputStream) Java.io.BufferedOutputStream ( OutputStream) Java.util.zip.ZipOutputStream (outputstream) java.util.collections#checkedlist| map| Set| Sortedset| SortedMap

Facade mode:

Provides a simple interface to a set of components, interfaces, abstractions, or subsystems. Java.lang.Class Javax.faces.webapp.FacesServlet

enjoy meta mode

Use caching to speed up access time for 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 mode

Proxy mode is a simple object that replaces a complex or time-consuming object. Java.lang.reflect.Proxy RMI creation pattern Abstract Factory pattern

The abstract factory pattern provides a protocol to generate a series of related or independent objects without specifying the type of the specific object. It enables applications to decouple from the concrete implementation of the framework used. This can be seen everywhere in the JDK or in many frameworks like spring. They are also easy to identify, a method of creating a new object that returns an interface or abstract class, and is an abstract factory pattern. 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 () construction mode (Builder)

A new class is defined to build an instance of another class to simplify the creation of complex objects. Construction patterns are often implemented using method links as well. Java.lang.stringbuilder#append () java.lang.stringbuffer#append () java.sql.PreparedStatement Javax.swing.grouplayout.group#addcomponent () factory method

is a way to return to a specific object. 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 mode

Enables instances of a class to generate copies of itself. If creating an instance of an object is very complex and time-consuming, you can use this pattern instead of recreating a new instance, you can copy an object and modify it directly. Java.lang.object#clone () java.lang.Cloneable single case mode

Used to ensure that a class has only one instance. Joshua Bloch is recommended in effetive Java, there is another way to use enumerations. Java.lang.runtime#getruntime () Java.awt.toolkit#getdefaulttoolkit () java.awt.graphicsenvironment# Getlocalgraphicsenvironment () java.awt.desktop#getdesktop () Behavioral pattern responsibility chain Model

Decoupling between objects by passing requests from one object to the next object in the chain until the request is processed. Java.util.logging.logger#log () javax.servlet.filter#dofilter () Command mode

Encapsulates an action within an object for storage, delivery, and return. Java.lang.Runnable javax.swing.Action Interpreter mode

This pattern usually defines the syntax of a language, and then parses the corresponding syntax statement. Java.util.Pattern java.text.Normalizer Java.text.Format iterator mode

Provides a consistent way to access objects in a collection sequentially, regardless of the actual implementation of the underlying collection. Java.util.Iterator java.util.Enumeration Intermediary model

Message distribution by using an intermediate object and reducing direct dependencies between classes. Java.util.Timer Java.util.concurrent.executor#execute () java.util.concurrent.executorservice#submit () Java.lang.reflect.method#invoke () Memo mode

Generates a snapshot of the state of an object so that the object can revert to its original state without exposing its contents. The Date object implements the memo pattern through a long value inside itself. Java.util.Date java.io.Serializable Empty object mode

This pattern replaces the state of no object with a meaningless object. It allows you to do no extra work on empty objects. Java.util.collections#emptylist () Java.util.collections#emptymap () Java.util.collections#emptyset () Observer mode

It allows an object to be flexible enough to send messages to objects of interest. Java.util.EventListener Javax.servlet.http.HttpSessionBindingListener Javax.servlet.http.HttpSessionAttributeListener Javax.faces.event.PhaseListener

State mode

By changing the internal state of an object, you can dynamically change the behavior of an object at run time. Java.util.Iterator Javax.faces.lifecycle.lifecycle#execute () policy mode

Use this pattern to encapsulate a set of algorithms into a series of objects. By passing these objects, you can change the function of the program flexibly. Java.util.comparator#compare () Javax.servlet.http.HttpServlet javax.servlet.filter#dofilter ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.