E
E
egorggegor2019-08-18 19:39:26
OOP
egorggegor, 2019-08-18 19:39:26

flyweight. Why do we need UnsharedConcreteFlyweight and ConcreteFlyweight?

I can't figure out why UnsharedConcreteFlyweight is needed in the Flyweight pattern? Many implement this pattern without this component. How to be with him and what does he do?
5d597f162ba48847494149.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2019-08-19
@egorggegor

Imagine that each flyweight instance should have a reference to an immutable 10k x 10k matrix. Since the pattern saves memory, it would be logical to keep the matrix in a single copy, despite the presence of a pool of opportunists. In ConcreteFlyweight this matrix is ​​stored. On the other hand, why do we need a pool of objects if they generally have all the same properties? UnsharedConcreteFlyweight is used to store differences.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question