All creation patterns of Java design patterns

Source: Internet
Author: User

Builder mode
Separate construction and assembly of components to construct complex objects

Singleton mode: Guarantees that there is only one instance of a class and provides a way to access the global access point constructor for that instance to privatize.

Singleton mode types: A hungry man, lazy, double lock, Static inner class, enumeration

A hungry man, double lock, enumeration cannot delay load lazy, static inner class where static inner class effect best thread safety, call efficiency, and implement delay loading!

The static inner class code is as follows

public class Singletondemo {private static class Singletonclassinstance {private static final Singletondemo instance = new Singletondemo ();} Private Singletondemo () {}//method is not synchronized, the call efficiency is high! public static Singletondemo  getinstance () {return singletonclassinstance.instance;}}

Factory mode (Simple Factory)
Used to produce any product in the same hierarchy the existing code needs to be modified for the new product
Not conforming to the open and closed principle is often used in the framework
Spring Create bean Factory all use

Factory method
For the production of fixed products in the same grade structure support to increase any product

Abstract Factory
All products for the production of different product families
Abstract product family can be added to the inability of the product

Prototype mode (copy, clone)
You need to implement the Cloneable interface using the Clone () method to copy a close () method such as a file stream
Creating an object with new requires very tedious data preparation or access permissions if you need to create a large number of objects in a short time and the new process is time consuming using prototype mode

Builder mode
Separate construction and assembly of components to construct complex objects

All creation patterns 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.