Search⌘ K
AI Features

Challenge: Flyweight Pattern

Understand how to apply the Flyweight pattern in JavaScript to prevent duplicate object instances. Learn to implement a DressFactory that creates dresses with unique serialNumbers, ensuring multiple references to the same object. This lesson helps develop skills for efficient coding interviews by focusing on structural pattern optimization and memory management.

Problem statement

In this challenge, you have been given the Dress class.

First, you need to define the dressPrice function, which is used to set the price of a dress and return it. The prices of different type of dresses are as follows:

  • maxi: 1000

  • gown: 2000

  • skirt: 500 ...