Instance -> Class -> Class Factory
Simply put, it is to encapsulate some classes with the same method and abstract the common method for invocation. It is an advanced version of the factory method.
Instance -> Class -> Class Factory -> Abstract Factory
This Python can be implemented using @property, which is generated when it is called.
The Builder mode is mainly used to construct a complex object, but the algorithm for constructing this object is stable, and various parts of the object often change. The Builder mode is mainly to deal with the frequent demand changes of various parts of complex objects. However, it is difficult to cope with changes in the demand for algorithms. You must pay attention to this point, if you use it wrong, it will bring a lot of unnecessary trouble.
The point is to abstract the construction process of complex objects (abstract category), so that different implementation methods of this abstract process can construct objects with different manifestations (attributes).
Simply put: the sub-object changes more frequently, and the algorithm is relatively stable.
There is only one instance of a class
The characteristic is to return a new instance by copying an existing instance instead of creating a new instance.
It is mostly used to create complex or time-consuming instances, because in this case, copying an existing instance makes the program run more efficiently; or creating similar data with equal values but different names.
An object pool is a set of objects that have been initialized and can be used, and objects can be created and destroyed when required. The user of the pool can obtain an object from the pool, manipulate it, and return it to the pool when it is not needed instead of destroying it instead of destroying it.
Object pool technology is implemented inside Python. For example, there are many data references like small integers, and creation and destruction will consume time, so it is stored in the object pool to reduce overhead.
Decorators are in Python.
For example, reference counting in Python.
Iterate over all the elements in the container.
Recommended Posts