create-flyweight
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-flyweight":https://skillpi.com/zh/skills/deepskill-63912fe0073d82035be4f0dce7a8bacb277e9547af626e81490aade857f1090b。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
为 PHP 8.4 生成享元模式实现。通过共享内部状态优化内存使用,并包含相应的单元测试。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 适合谁
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
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
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 PHP 8.4 享元模式完整代码生成方案,包含接口、实现、工厂和单元测试
- 涵盖常见应用场景(货币、图标、税率等)和最佳实践,实用性强
待提升项
-
触发词缺失 原报告严重程度:轻微
未在顶层 frontmatter 中定义具体触发关键词或命令格式,仅靠 description 内容推断
改进建议:建议在 frontmatter 中添加 keywords 字段,明确触发词如 'generate flyweight', 'create flyweight pattern' 等
亮点
- description 内容清晰描述了核心功能(PHP 8.4 享元模式生成)
亮点
- 文档结构完整,包含使用场景、生成步骤、文件路径、命名规范、模板和示例
- 提供了详细的代码模板和实际使用示例,便于用户理解和应用
待提升项
-
异常处理缺失 原报告严重程度:轻微
未说明生成文件时如何处理路径冲突、文件覆盖等异常情况
改进建议:建议添加异常处理说明,如文件存在时的处理策略、路径验证等
亮点
- 提供了完整的代码模板和工厂实现,逻辑清晰可靠
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。