Skip to content

Commit 67f5b4a

Browse files
committed
Add README.
1 parent 8e0485f commit 67f5b4a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Flyweight Pattern
2+
Flyweight is a structural design pattern that lets you fit more objects into the available amount of
3+
RAM by sharing common parts of state between multiple objects instead of keeping all of the data in
4+
each object.
5+
6+
Tutorial: [here](https://refactoring.guru/design-patterns/flyweight).
7+
8+
### Conceptual Diagram:
9+
![Flyweight Pattern Diagram](https://user-images.githubusercontent.com/8049534/174476638-007f3179-495f-499d-8f35-e33956d4890b.png)
10+
11+
### Client code:
12+
```dart
13+
void main() {
14+
final factory = FlyweightFactory();
15+
16+
final one = factory.create('one');
17+
one.draw();
18+
19+
final ONE = factory.create('ONE');
20+
ONE.draw();
21+
22+
final OnE = factory.create('OnE');
23+
OnE.draw();
24+
25+
final two = factory.create('two');
26+
two.draw();
27+
28+
final Two = factory.create('Two');
29+
Two.draw();
30+
}
31+
```
32+
33+
### Output:
34+
```
35+
Flyweight(
36+
localParam: "one", shareParam: (61, "b", 0.19)
37+
)
38+
Flyweight(
39+
localParam: "ONE", shareParam: (61, "b", 0.19)
40+
)
41+
Flyweight(
42+
localParam: "OnE", shareParam: (61, "b", 0.19)
43+
)
44+
Flyweight(
45+
localParam: "two", shareParam: (53, "e", 0.55)
46+
)
47+
Flyweight(
48+
localParam: "Two", shareParam: (53, "e", 0.55)
49+
)
50+
```

0 commit comments

Comments
 (0)