Flyweight vs object pool patterns: When is each useful?

前端 未结 3 503
抹茶落季
抹茶落季 2020-12-29 23:54

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 some

3条回答
  •  一整个雨季
    2020-12-30 00:46

    At least two major differences come to mind:

    • An object pool is a container for a set of domain objects while a flyweight usually is a domain object.
    • An object pool usually contains a set of similar objects that can be shared concurrently, such as database connections, while there is usually a set of different flyweight objects, each representing a different state.

提交回复
热议问题