Design patterns implementation examples

Flyweight

Definition:

Reduces memory consumption and creationation time by sharing objects in some state. A client can create only one sample of an object in some state and then after customizing it he can use it for his own purpose.


Example:

When all the household uses the same device we save money. For instance - we do not buy hair dryer for each family member. Hair dryer has several different functions and each inmate uses it as he or she prefers.


C++ code:

/src/flyweight.cpp
Download source code

Flyweight UML class diagram:
Flyweight UML class diagram

Flyweight UML sequence diagram:
Flyweight UML sequence diagram