dykyi-roman/awesome-claude-code/create-flyweight

Trust tier 2
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Generates Flyweight pattern for PHP 8.4. Optimizes memory via shared intrinsic state. Includes unit tests.

Install

npx vskill@latest install dykyi-roman/awesome-claude-code/create-flyweight

SKILL.md

Flyweight Pattern Generator

Creates Flyweight pattern infrastructure for memory optimization through object sharing.

When to Use

ScenarioExample
Large number of similar objectsIcons, glyphs, particles
Memory constraintsMobile apps, embedded systems
Immutable shared stateCurrency codes, tax rates
Performance optimizationReduce object creation overhead

Component Characteristics

Flyweight Interface
  • Defines operations
  • Accepts extrinsic state as parameters
ConcreteFlyweight
  • Stores intrinsic state (shared)
  • Immutable
  • Reusable across contexts
FlyweightFactory
  • Creates and manages flyweights
  • Returns existing or new flyweight
  • Ensures sharing

Generation Process

Step 1: Generate Flyweight Interface

Path: src/Domain/{BoundedContext}/

  1. {Name}Interface.php — Operations contract
Step 2: Generate ConcreteFlyweight

Path: src/Domain/{BoundedContext}/

  1. {Name}Flyweight.php — Shared object
Step 3: Generate FlyweightFactory

Path: src/Domain/{BoundedContext}/Factory/ or src/Infrastructure/

  1. {Name}FlyweightFactory.php — Manages flyweights
Step 4: Generate Tests
  1. {ClassName}Test.php — Flyweight behavior and sharing verification

File Placement

ComponentPath
Flyweight Interfacesrc/Domain/{BoundedContext}/
ConcreteFlyweightsrc/Domain/{BoundedContext}/
FlyweightFactorysrc/Domain/{BoundedContext}/Factory/
Unit Teststests/Unit/Domain/{BoundedContext}/

Naming Conventions

ComponentPatternExample
Flyweight Interface{Name}InterfaceCurrencyInterface
ConcreteFlyweight{Name}FlyweightCurrencyFlyweight
FlyweightFactory{Name}FlyweightFactoryCurrencyFlyweightFactory
Test{ClassName}TestCurrencyFlyweightTest

Quick Template Reference

Flyweight
php
final readonly class {Name}Flyweight implements {Name}Interface
{
public function __construct(
private string $intrinsicState
) {}
public function {operation}(string $extrinsicState): {returnType}
{
return {combine intrinsic and extrinsic state};
}
}
FlyweightFactory
php
final class {Name}FlyweightFactory
{
private array $flyweights = [];
public function getFlyweight(string $key): {Name}Interface
{
if (!isset($this->flyweights[$key])) {
$this->flyweights[$key] = new {Name}Flyweight($key);
}
return $this->flyweights[$key];
}
public function getCount(): int
{
return count($this->flyweights);
}
}

Usage Example

php
$factory = new CurrencyFlyweightFactory();
// Same object returned
$usd1 = $factory->getFlyweight('USD');
$usd2 = $factory->getFlyweight('USD');
assert($usd1 === $usd2); // true
// Format with extrinsic state
$usd1->format(100.50); // "$100.50"

Common Flyweights

FlyweightPurpose
CurrencyFlyweightCurrency codes and symbols
IconFlyweightUI icons
TaxRuleFlyweightTax rates by region
CharacterFlyweightText rendering glyphs
ColorFlyweightColor palettes

Anti-patterns to Avoid

Anti-patternProblemSolution
Mutable FlyweightState changes affect all usersMake flyweights immutable
No FactoryManual object managementUse flyweight factory
Large Intrinsic StateMemory not optimizedKeep intrinsic state minimal
Extrinsic in FlyweightNot reusablePass extrinsic via parameters
Premature OptimizationComplexity without benefitProfile first

References

For complete PHP templates and examples, see:

  • references/templates.md — Flyweight, factory templates
  • references/examples.md — Currency, icon, tax rule flyweights with unit tests

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
96
Repository forks
25
7-day trend score
23

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/dykyi-roman/awesome-claude-code/create-flyweight/badge)](https://verified-skill.com/skills/dykyi-roman/awesome-claude-code/create-flyweight)

Something wrong with this skill or its page? Tell us.