7
← Back to Pattern Arsenal
structural

Flyweight

rare

Stage 1: Problem

Problem

You are building a real-time analytics dashboard that renders 50,000 log entries. Each entry has a severity level (info, warn, error, fatal), an icon, a color scheme, and font styling. But most entries share the same severity — 40,000 are "info", 8,000 are "warn", 1,500 are "error", 500 are "fatal". Creating a full styling object for each of the 50,000 entries wastes memory — you are duplicating the same icon, color, and font data thousands of times.

Before continuing, think: how would you share the common styling data across thousands of entries without duplicating it?

1 / 10 — Problem