File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
patterns/flyweight/conceptual Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments