Mid From PDF GoF Patterns Gang of Four Patterns

Flyweight Factory (CharacterFactory):?

Short answer: The CharacterFactory is responsible for managing the flyweights. It keeps track of the existing character objects and ensures that no duplicate instances of the same character are created. If a character already exists in the dictionary, it is reused. Otherwise, a new Character object is created and stored for future use. public class CharacterFactory

Example code

{
private readonly Dictionary<char, Character> _characters = new
Dictionary<char, Character>();
public Character GetCharacter(char symbol)
{
if (!_characters.ContainsKey(symbol))
{
_characters[symbol] = new Character(symbol);
}
return _characters[symbol];
}
}

Real-world example (ShopNest)

ShopNest’s NotificationFactory creates Email or SMS senders based on user preference.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details