Design Pattern of Curriculum Design 8-1 singleton succinctly explain

1 Class Overview

1.1 Definitions

1.2 application scenarios

1.3 advantage

1.4 shortcomings

 

1 Class Overview

1.1 Definitions

Definition: to ensure that only one instance of a class, and provide a global access point

Type: Creating type

 

1.2 usage scenarios

a ◆ absolutely want to make sure that only one instance of any case

b When an object needs to be created frequently destroyed when, and created or destroyed unable to optimize performance

E.g:

Order of service website counter can use a singleton;

EXAMPLE single mode where the thread pool;

Database connection pool can also use the singleton;

 

1.3 advantage

In only one instance of a memory, reducing memory overhead

b avoid multiple assignment of resources

c set global access point, and strictly control access (Foreign not be new come out, can not be instantiated)

 

1.4 shortcomings

 No interface is hard to expand

Guess you like

Origin www.cnblogs.com/1446358788-qq/p/11354816.html