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