Skip to content

Commit 38fda6e

Browse files
committed
Added flyweight to readme
1 parent 280cd23 commit 38fda6e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,24 @@ Other patterns:
4040
## 1. Command
4141

4242

43+
4344
## 2. Flyweight
4445

46+
This pattern is useful if you have many objects. Even though a single object takes up little memory – instantiating many of them can cause trouble.
47+
48+
**How to implement?**
49+
50+
* Separate the data that’s not specific to a single instance of that object and can be shared across all of them. You do that by creating a new class and put the shared data in it. Then each object that should share data gets a reference to a single instance of that "storage" class.
51+
52+
**When is it useful?**
53+
54+
* If you make Minecraft and have a million cubes in the scene. All cubes can share the same texture if you put all textures that belongs to each cube type (grass, stone, sand, etc) into a [texture atlas](https://en.wikipedia.org/wiki/Texture_atlas).
55+
56+
**Related patterns**
57+
58+
* Type object(#12-type-object). The main difference is that in Type object you don't need to have the exact same data and you can also have behavior.
59+
60+
4561

4662
## 3. Observer
4763

0 commit comments

Comments
 (0)