From acc
Generates Composite pattern for PHP 8.4 with interface, leaf, composite classes, and unit tests. For tree structures like menus, file systems, org charts.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-compositeThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Creates Composite pattern infrastructure for treating individual objects and compositions uniformly.
Creates Composite pattern infrastructure for treating individual objects and compositions uniformly.
| Scenario | Example |
|---|---|
| Tree structures | Menus, file systems, organization charts |
| Part-whole hierarchies | UI components, product categories |
| Recursive operations | Calculate totals, render trees |
| Uniform treatment | Same interface for leaf and composite |
Path: src/Domain/{BoundedContext}/
{Name}Interface.php — Operations contractPath: src/Domain/{BoundedContext}/
{Name}Leaf.php — Individual objectPath: src/Domain/{BoundedContext}/
{Name}Composite.php — Container for children{ClassName}Test.php — Component behavior verification| Component | Path |
|---|---|
| Component Interface | src/Domain/{BoundedContext}/ |
| Leaf | src/Domain/{BoundedContext}/ |
| Composite | src/Domain/{BoundedContext}/ |
| Unit Tests | tests/Unit/Domain/{BoundedContext}/ |
| Component | Pattern | Example |
|---|---|---|
| Component Interface | {Name}Interface | MenuItemInterface |
| Leaf | {Name} | MenuItem |
| Composite | {Name}Composite | MenuComposite |
| Test | {ClassName}Test | MenuCompositeTest |
interface {Name}Interface
{
public function {operation}(): {returnType};
}
final readonly class {Name} implements {Name}Interface
{
public function {operation}(): {returnType}
{
return {leafBehavior};
}
}
final class {Name}Composite implements {Name}Interface
{
private array $children = [];
public function add({Name}Interface $child): void
{
$this->children[] = $child;
}
public function {operation}(): {returnType}
{
$result = {initialValue};
foreach ($this->children as $child) {
$result {combineOperation} $child->{operation}();
}
return $result;
}
}
$menu = new MenuComposite('Products');
$menu->add(new MenuItem('Laptops'));
$submenu = new MenuComposite('Accessories');
$submenu->add(new MenuItem('Mouse'));
$submenu->add(new MenuItem('Keyboard'));
$menu->add($submenu);
// Uniform treatment
$menu->render();
| Composite | Purpose |
|---|---|
| MenuComposite | Nested menu structures |
| PermissionComposite | Permission hierarchies |
| PriceRuleComposite | Combined pricing rules |
| FileSystemComposite | Files and directories |
| OrganizationComposite | Company structure |
| Anti-pattern | Problem | Solution |
|---|---|---|
| Type Checking | instanceof checks everywhere | Use polymorphism |
| Leaf Operations in Composite | add/remove on leafs | Throw exception or use separate interfaces |
| Deep Hierarchies | Performance issues | Limit depth or use flyweight |
| Missing Parent Reference | Can't navigate up | Store parent in composite |
| Circular References | Infinite loops | Validate before adding |
For complete PHP templates and examples, see:
references/templates.md — Component interface, leaf, composite templatesreferences/examples.md — Menu, permission, price rule composites with unit testsnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accGenerates Decorator pattern for PHP 8.4: interface, abstract decorator, concrete decorators (logging, caching, metrics, transactional), optional factory, and unit tests. For dynamic behavior without inheritance.
Applies the Composite design pattern to compose objects into tree structures, enabling uniform treatment of leaf and container nodes for part-whole hierarchies.
Covers 26 Gang of Four design patterns with PHP 8.3+ implementations, UML diagrams, and practical use cases.