- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Flyweight Design Pattern Explained: Save Memory with Shared Objects
Learn how the Flyweight design pattern makes millions of objects memory-efficient by separating shared data from data unique to each instance. Using a forest of a million trees as a running example, this tutorial shows how to slash memory usage by sharing heavy intrinsic state across countless objects.
We start with a naive Tree class where every object duplicates its name, color, texture, and mesh—ballooning memory into the red. Then we refactor step by step into a clean Flyweight implementation backed by a factory cache.
What this video covers:
- What the Flyweight pattern is and the problem it solves
- The difference between intrinsic state (shared: name, color, texture, mesh) and extrinsic state (unique: x, y coordinates)
- Building a TreeType flyweight that holds only the heavy shared data
- Using a TreeFactory cache with getTreeType to reuse instances by name and color
- Refactoring the Tree class to store just x, y, and a single TreeType reference
- How a Forest holds thousands of Trees that all share one TreeType
- Comparing the before and after versions to see dramatic memory savings
- Passing extrinsic state into the draw method at render time
By the end, you'll understand how to separate intrinsic state into a flyweight, pass extrinsic state per call, and reuse instances through a factory cache for lightweight, memory-friendly objects.
#Flyweight #DesignPatterns #SoftwareDesign #OOP #Programming #MemoryOptimization #SoftwareEngineering #CodingTutorial
Видео Flyweight Design Pattern Explained: Save Memory with Shared Objects канала Alfa Yohannis
We start with a naive Tree class where every object duplicates its name, color, texture, and mesh—ballooning memory into the red. Then we refactor step by step into a clean Flyweight implementation backed by a factory cache.
What this video covers:
- What the Flyweight pattern is and the problem it solves
- The difference between intrinsic state (shared: name, color, texture, mesh) and extrinsic state (unique: x, y coordinates)
- Building a TreeType flyweight that holds only the heavy shared data
- Using a TreeFactory cache with getTreeType to reuse instances by name and color
- Refactoring the Tree class to store just x, y, and a single TreeType reference
- How a Forest holds thousands of Trees that all share one TreeType
- Comparing the before and after versions to see dramatic memory savings
- Passing extrinsic state into the draw method at render time
By the end, you'll understand how to separate intrinsic state into a flyweight, pass extrinsic state per call, and reuse instances through a factory cache for lightweight, memory-friendly objects.
#Flyweight #DesignPatterns #SoftwareDesign #OOP #Programming #MemoryOptimization #SoftwareEngineering #CodingTutorial
Видео Flyweight Design Pattern Explained: Save Memory with Shared Objects канала Alfa Yohannis
flyweight pattern flyweight design pattern design patterns software design patterns OOP object oriented programming intrinsic state extrinsic state factory cache memory optimization TreeType TreeFactory GoF patterns structural patterns software engineering programming tutorial code refactoring memory efficiency shared objects object pooling
Комментарии отсутствуют
Информация о видео
16 июня 2026 г. 10:43:53
00:02:20
Другие видео канала





















