lec 40: structural design patterns, part 5

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:25 PM on 4/13/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

20 Terms

1
New cards

What is the Flyweight pattern?

A pattern that uses sharing to support large numbers of fine-grained objects efficiently.

2
New cards

What problem does Flyweight solve?

It reduces memory usage when an application has huge numbers of very similar objects.

3
New cards

What is the definition of Flyweight?

Use sharing to support large numbers of fine-grained objects efficiently.

4
New cards

What is the motivating example in the slides?

A role-playing game with huge numbers of terrain objects like trees and mountains.

5
New cards

Why is memory a problem in the terrain example?

Because millions of terrain objects and repeated sprite images would consume too much memory.

6
New cards

When should Flyweight be used?

When an application uses a large number of objects and storage costs are high.

7
New cards

What is intrinsic state?

State stored inside the flyweight that is independent of context and can be shared.

8
New cards

What is extrinsic state?

State that depends on context, varies between uses, and cannot be shared.

9
New cards

In the terrain example, what is intrinsic state?

The sprite image, such as tree.png.

10
New cards

In the terrain example, what is extrinsic state?

The x and y position where the terrain is drawn.

11
New cards

Why is object identity an issue in Flyweight?

Because shared flyweights may be reused for conceptually different objects, so identity tests can be misleading.

12
New cards

What is the role of the FlyweightFactory?

It manages a pool of flyweights and returns an existing one when possible instead of creating duplicates.

13
New cards

What does the factory do if a requested flyweight already exists?

It returns the existing shared flyweight.

14
New cards

What does the factory do if a requested flyweight does not exist?

It creates it, stores it, and returns it.

15
New cards

What happens without Flyweight in the tree example?

One million Tree objects are created and tree.png is loaded one million times.

16
New cards

What happens with Flyweight in the tree example?

One shared terrain object is reused and tree.png is loaded only once.

17
New cards

What is the main benefit of Flyweight?

Reduced memory requirements.

18
New cards

What is one downside of Flyweight?

It may introduce runtime costs for passing or computing extrinsic state and finding flyweights.

19
New cards

What is the key exam distinction in Flyweight?

Separate shared intrinsic state from unshared extrinsic state.

20
New cards

What is a good memory trick for Flyweight?

Share what stays the same, pass in what changes.