I need write permission to create the entry file. Here's the structured summary I've prepared:

GoF Composite and Decorator Structural Patterns

This entry covers two structural patterns from the Gang of Four catalog—Composite and Decorator—that both use recursive composition through a common interface but for different purposes. Composite models part-whole hierarchies so clients treat individual objects and collections uniformly. Decorator wraps objects to add responsibilities dynamically without subclassing.

---

Key Concepts

Composite Pattern

Decorator Pattern

Commands and Syntax

Composite — GetComposite for safe downcasting (C++)


virtual Composite* GetComposite() { return 0; }       // Component default
virtual Composite* GetComposite() { return this; }     // Composite override

if (test = aComponent->GetComposite()) {
    test->Add(new Leaf);  // safe — only executes on actual composites
}

Composite — Equipment hierarchy example


class Equipment {
public:
    virtual Watt Power();
    virtual Currency NetPrice();
    virtual void Add(Equipment*);
    virtual void Remove(Equipment*);
    virtual Iterator<Equipment*>* CreateIterator();
};

// Assembly
Cabinet* cabinet = new Cabinet("PC Cabinet");
Chassis* chassis = new Chassis("PC Chassis");
cabinet->Add(chassis);
chassis->Add(new FloppyDisk("3.5in Floppy"));
cout << chassis->NetPrice() << endl;

Relationships

Exam-Relevant Points

1. Composite's defining characteristic: Clients treat Leaf and Composite uniformly—no conditional type checking needed.

2. Transparency vs. safety: Add/Remove in Component = transparency. Add/Remove only in Composite = safety. GoF emphasizes transparency.

3. Decorator preserves interface: Must conform to Component interface, making decoration transparent.

4. Decorator breaks object identity: A decorated object is not identical to the original.

5. Decorator vs. inheritance: Run-time per-instance (Decorator) vs. static per-class (inheritance). Decorator avoids subclass explosion.

6. Decorator vs. Strategy: Skin vs. guts. Strategy can have a specialized interface; Decorator must match Component's interface.

7. Composite implementation issues: Parent references, component sharing (Flyweight), maximizing Component interface, child ordering (Iterator), caching (with invalidation), storage structure choice, deletion responsibility.

8. Decorator implementation issues: Interface conformance, can omit abstract Decorator class for single responsibility, keep Component lightweight.

9. Composite weakness: Overly general—can't restrict valid children via the type system.

10. Decorator weakness: Many small look-alike objects—hard to learn and debug.

---

Would you like me to retry writing this to the entries directory, or should I proceed differently?