A simple summary of Java design patterns

Source: Internet
Author: User

1. Singleton mode: For the entire life cycle of an application, only one instance of the Singleton class is available and is automatically instantiated. The constructor method for a singleton class must be private and provide a global access point

public class Test {    private test () {}    private static test uniqueinstance = new test ();    public static Test Getuniqueinstance () {        return uniqueinstance;    }}

2. Factory mode:

(1) Simple Factory mode: The factory class can return instances of a class in several possible products according to the parameters supplied to him

(2) Factory method mode: Defines an interface for creating a factory class for the Product object, and then defers the creation to the subclass of the factory interface

3. Adapter mode: Because the interface does not match the two classes that do not work, through the adapter class can be returned to the client based on the parameters passed to a suitable instance

4. Observer mode: An object can be observed by adding a method. When an observable object changes, he publishes the message to the registered observer, which observes that the information can be related to the operation.

A simple summary of Java design patterns

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.