As far as I know the object pool is a creational pattern and the flyweight is a structural pattern, but actually I can´t see very much difference between the two. Could someone please explain to me the difference and when each could be useful in an implementation?
相关问题
- Name for a method that has only side effects
- What is a correct approach to manage test data usi
- Can a [GoF]-ConcreteSubject override the notify me
- Can the builder pattern ever be doing too much?
- Carry STRef implicitly in an environment during co
One difference in that flyweights are commonly immutable instances, while resources acquired from the pool usually are mutable.
So you create flyweights to avoid the cost of repeatedly create multiple instances of objects containing the same state (because they are all the same, you just create only one and reuse it throughout all places in your app), while resources in a pool are particular resources that you want to control individually and possibly have different state, but you don't want to pay the cost of creation and destruction because they are all initialized in the same state.
At least two major differences come to mind:
This site describes both patterns with specific examples. It does a pretty goo job clarifying the difference and supports Gabriel's response above. http://www.oodesign.com/