Flyweight Pattern — Concept Check
Questions on Flyweight Pattern. Uses sharing to support large numbers of fine-grained objects efficiently by separating intrinsic (shared) state from extrinsic (context-specific) state.
Questions in this quiz
8 questions on Flyweight Pattern — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A text editor renders thousands of 'A' characters using a Flyweight pattern. How many CharacterGlyph instances are created?
- ADepends on the color
- BDepends on the font and size
- C1000
- D1
2.In Java, two Integer objects are created with Integer.valueOf(127) and Integer.valueOf(127). What is the result of comparing them with '=='?
- ADepends on Integer cache size
- Bfalse
- CDepends on JVM settings
- Dtrue
3.A developer uses a Flyweight pattern for chess pieces. What is stored in the flyweight?
- AColor
- BPieceType
- CAlive status
- DPosition
4.A system uses Flyweight to manage icons. Which state should be extrinsic?
- APosition on screen
- BDefault color
- CIcon size
- DIcon shape
5.Why might a Flyweight pattern increase CPU usage?
- AExtrinsic state is stored in the Flyweight
- BFlyweight objects are larger
- CPassing extrinsic state requires more computation
- DIntrinsic state increases memory usage
6.A developer believes Flyweight is unsuitable for applications with few objects. Why is this incorrect?
- AFlyweight benefits are minimal with few objects
- BFlyweight needs a factory pattern
- CFlyweight increases complexity
- DFlyweight requires large memory
7.In a Flyweight implementation, what role does the FlyweightFactory play?
- ACaches and reuses shared instances
- BManages object lifecycle
- CCreates new instances for each request
- DStores extrinsic state
8.A developer uses new String("hello") instead of a literal. What is the result?
- AReuses an existing object
- BCreates a new object on the heap
- CUses the string pool
- DThrows an exception