0% found this document useful (0 votes)
2K views12 pages

Flyweight Pattern in JavaScript

The Flyweight pattern is used to improve performance and efficiency when large numbers of similar objects are created. It works by removing extrinsic/non-shared data from objects to make them lightweight flyweights, creating a factory to store and return flyweight objects, and using a manager class to encapsulate and provide extrinsic data to flyweights. While it improves performance and reduces resources, it also makes debugging harder and requires more maintenance effort.

Uploaded by

Kyungwook Park
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views12 pages

Flyweight Pattern in JavaScript

The Flyweight pattern is used to improve performance and efficiency when large numbers of similar objects are created. It works by removing extrinsic/non-shared data from objects to make them lightweight flyweights, creating a factory to store and return flyweight objects, and using a manager class to encapsulate and provide extrinsic data to flyweights. While it improves performance and reduces resources, it also makes debugging harder and requires more maintenance effort.

Uploaded by

Kyungwook Park
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

The Flyweight Pattern

in JavaScript
When
• large numbers of similar objects are created,
causing performance problems.
Implementing the Flyweight Pattern

1. Remove all extrinsic data


2. Create a factory
3. Create a manager
(to store the extrinsic data)
1. Remove all extrinsic data

Intrinsic Data

Extrinsic Data
1. Remove all extrinsic data
2. Create a factory

Store into share object


3. Create a manager

Store into share object

Extrinsic Data
3. Create a manager
Managing extrinsic data
• Encapsulated in a Manager Class
• Use composite Pattern
– leaf nodes can all be flyweight objects!
Summary
• Benefits
– Improve performance
– Make a code more efficient
– Reduce page resources

• Drawbacks
– Harder to debug
• Manager/Factory/Flyweight object
– Maintenance
References
• http://ko.wikipedia.org/wiki/플라이웨이트_패턴
• Chapter 13, Pro JavaScript Design Patterns - Apress

You might also like