Curriculum design patterns Design patterns succinctly explain 13-1 Flyweight

1 The course explains

1.1 Type:

1.2 Definitions:

1.3 application scenarios:

1.4 Advantages:

1.5 Disadvantages:

1.6 Extensions:

1.7 design patterns and other comparison:

 

1 The course explains
1.1 Type:

Structural:

 

1.2 Definitions:

◆ Definition: Provides a reduction in the number of objects in order to improve the object structure required for the application of ways
◆ Use sharing to support large numbers of fine-grained objects

(Possible solutions for the problem of effective memory overflow type) (pool)

 

1.3 application scenarios:

◆ a system often used in the development of the underlying, in order to solve the performance problems of the system.

( The system if there are a large number of objects may cause memory overflow, we can put together a part of the abstract, the same service request, existing objects in memory returns, to avoid re-created. )


◆ b system has a large number of similar objects, scenes need to buffer pool.

(The higher the reusability of an object, the more inclined to use Flyweight)

 

1.4 Advantages:

◆ Reduce create objects, reduce the number of objects in memory to reduce the memory system, improve efficiency
◆ reduce resource consumption than other memory

(A new object requires time, when we take objects directly from the pool, the objects do not create, save time, especially when the object or concurrent usage is relatively high, improving the efficiency

   b file handles and window handles are certain restrictions when the same object is particularly large, it often may cause the handle to the limit and cause a crash)

 

1.5 Disadvantages:

◆ attention inside / outside the state, concerned about the security thread

We use the share mode time, mostly using hashMap, will not use HashTable (with hashTable due to synchronization lock caused by low efficiency (in particular the application of the system to apply for three days to log how many people, one day micro broad circumstances of the incident))


◆ of the system, complicated logic

With external state should not change the internal state changes

 

1.6 Extensions:

Internal state:

Flyweight pattern inside and will not be shared with part of the environment changes and changes; regardless of the external environment changes, I will remain unchanged, and the state share in the internal metadata model.

 

External state:

With the environmental change is external changes state, this state is recorded in the external Flyweight mode.

 

1.7 design patterns and other comparison:

Flyweight mode and proxy mode:

Proxy mode is a proxy class, if the generated proxy class resources and time to spend more, you can use the Flyweight pattern processing speed of this class.

 

Flyweight and Singleton:

Single vessel embodiment is a combination of the two. Flyweight pattern is a reusable objects of thought

 

Guess you like

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