Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the practical use differences between Flyweight vs Singleton patterns?

Tags:

The two pattern seems to achieve the same thing. What are the different use cases in real world? Thanks

like image 253
Kuzey Avatar asked May 25 '13 14:05

Kuzey


1 Answers

Flyweight is when you have many different kinds of a single thing.

Singleton is when you have a single thing.

For example, you might use the Flyweight Pattern to represent keyboard characters. One object for a, one for b, etc. They are both characters, but different kinds of characters.

In contrast, you might use a singleton to represent the keyboard. There can only be one.

like image 80
Tim Pote Avatar answered Oct 20 '22 08:10

Tim Pote