create-flyweight
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "create-flyweight" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-63912fe0073d82035be4f0dce7a8bacb277e9547af626e81490aade857f1090b. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Generate a Flyweight pattern implementation for PHP 8.4. Optimize memory by sharing intrinsic state, and include corresponding unit tests.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Generates Flyweight pattern for PHP 8.4. Optimizes memory via shared intrinsic state. Includes unit tests.
- Audience
- | Scenario | Example | |----------|---------| | Large number of similar objects | Icons, glyphs, particles | | Memory constraints | Mobile apps, embedded systems | | Immutable shared state | Currency codes, tax rates | | Performance optimization | Reduce object creation overhead |
- Testing
- Not tested
Browse files
Frontmatter
name: create-flyweight
description: Generates Flyweight pattern for PHP 8.4. Optimizes memory via shared intrinsic state. Includes unit tests.Flyweight Pattern Generator
Creates Flyweight pattern infrastructure for memory optimization through object sharing.
When to Use
| Scenario | Example |
|---|---|
| Large number of similar objects | Icons, glyphs, particles |
| Memory constraints | Mobile apps, embedded systems |
| Immutable shared state | Currency codes, tax rates |
| Performance optimization | Reduce 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}/
{Name}Interface.php— Operations contract
Step 2: Generate ConcreteFlyweight
Path: src/Domain/{BoundedContext}/
{Name}Flyweight.php— Shared object
Step 3: Generate FlyweightFactory
Path: src/Domain/{BoundedContext}/Factory/ or src/Infrastructure/
{Name}FlyweightFactory.php— Manages flyweights
Step 4: Generate Tests
{ClassName}Test.php— Flyweight behavior and sharing verification
File Placement
| Component | Path |
|---|---|
| Flyweight Interface | src/Domain/{BoundedContext}/ |
| ConcreteFlyweight | src/Domain/{BoundedContext}/ |
| FlyweightFactory | src/Domain/{BoundedContext}/Factory/ |
| Unit Tests | tests/Unit/Domain/{BoundedContext}/ |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Flyweight Interface | {Name}Interface |
CurrencyInterface |
| ConcreteFlyweight | {Name}Flyweight |
CurrencyFlyweight |
| FlyweightFactory | {Name}FlyweightFactory |
CurrencyFlyweightFactory |
| Test | {ClassName}Test |
CurrencyFlyweightTest |
Quick Template Reference
Flyweight
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
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
$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
| Flyweight | Purpose |
|---|---|
| CurrencyFlyweight | Currency codes and symbols |
| IconFlyweight | UI icons |
| TaxRuleFlyweight | Tax rates by region |
| CharacterFlyweight | Text rendering glyphs |
| ColorFlyweight | Color palettes |
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| Mutable Flyweight | State changes affect all users | Make flyweights immutable |
| No Factory | Manual object management | Use flyweight factory |
| Large Intrinsic State | Memory not optimized | Keep intrinsic state minimal |
| Extrinsic in Flyweight | Not reusable | Pass extrinsic via parameters |
| Premature Optimization | Complexity without benefit | Profile first |
References
For complete PHP templates and examples, see:
references/templates.md— Flyweight, factory templatesreferences/examples.md— Currency, icon, tax rule flyweights with unit tests
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 PHP 8.4 享元模式完整代码生成方案,包含接口、实现、工厂和单元测试
- 涵盖常见应用场景(货币、图标、税率等)和最佳实践,实用性强
Areas to improve
-
触发词缺失 Reported severity: Minor
未在顶层 frontmatter 中定义具体触发关键词或命令格式,仅靠 description 内容推断
Recommendation: 建议在 frontmatter 中添加 keywords 字段,明确触发词如 'generate flyweight', 'create flyweight pattern' 等
Highlights
- description 内容清晰描述了核心功能(PHP 8.4 享元模式生成)
Highlights
- 文档结构完整,包含使用场景、生成步骤、文件路径、命名规范、模板和示例
- 提供了详细的代码模板和实际使用示例,便于用户理解和应用
Areas to improve
-
异常处理缺失 Reported severity: Minor
未说明生成文件时如何处理路径冲突、文件覆盖等异常情况
Recommendation: 建议添加异常处理说明,如文件存在时的处理策略、路径验证等
Highlights
- 提供了完整的代码模板和工厂实现,逻辑清晰可靠
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.