Facade Pattern Generator
Creates Facade pattern infrastructure for providing simplified access to complex subsystems.
When to Use
| Scenario |
Example |
| Complex subsystem simplification |
Order facade combining inventory, payment, shipping |
| Multiple service orchestration |
Notification facade coordinating email, SMS, push |
| Legacy system wrapping |
Facade hiding complex legacy APIs |
| Layered system access |
Application layer facade for domain services |
Component Characteristics
Facade
- Simple unified interface
- Delegates to subsystem classes
- No business logic, only orchestration
- Lives in Application layer
Subsystem Classes
- Independent complex operations
- Can be used directly or through facade
- Domain or Infrastructure services
Generation Process
Step 1: Generate Facade
Path: src/Application/{BoundedContext}/Facade/
{Name}Facade.php — Unified interface to subsystem
Step 2: Identify Subsystem Classes (Existing)
Paths: Domain or Infrastructure services
- Services, Repositories, External APIs
- Multiple components with related functionality
Step 3: Generate Tests
{FacadeName}Test.php — Facade orchestration verification
File Placement
| Component |
Path |
| Facade |
src/Application/{BoundedContext}/Facade/ |
| Subsystem Classes |
src/Domain/ or src/Infrastructure/ |
| Unit Tests |
tests/Unit/Application/{BoundedContext}/Facade/ |
Naming Conventions
| Component |
Pattern |
Example |
| Facade |
{Name}Facade |
OrderFacade |
| Test |
{ClassName}Test |
OrderFacadeTest |
Quick Template Reference
Facade
final readonly class {Name}Facade
{
public function __construct(
private {SubsystemA} $subsystemA,
private {SubsystemB} $subsystemB,
private {SubsystemC} $subsystemC
) {}
public function {complexOperation}({params}): {returnType}
{
$stepA = $this->subsystemA->{methodA}({params});
$stepB = $this->subsystemB->{methodB}($stepA);
$stepC = $this->subsystemC->{methodC}($stepB);
return $stepC;
}
}
Usage Example
// Without facade - complex coordination
$inventory = $inventoryService->reserve($productId, $quantity);
$payment = $paymentService->charge($amount, $token);
$shipment = $shippingService->schedule($address, $inventory);
$order = $orderRepository->save(new Order(...));
$notificationService->sendConfirmation($order);
// With facade - simple call
$order = $orderFacade->placeOrder($command);
Common Facades
| Facade |
Purpose |
| OrderFacade |
Coordinate inventory, payment, shipping, notifications |
| NotificationFacade |
Send via email, SMS, push, Slack |
| ReportFacade |
Generate PDF, Excel, CSV reports |
| UserRegistrationFacade |
Validate, create account, send welcome email |
| PaymentFacade |
Authorize, charge, record, notify |
| ExportFacade |
Fetch data, transform, format, save file |
Anti-patterns to Avoid
| Anti-pattern |
Problem |
Solution |
| God Facade |
Facade does too much |
Split into focused facades |
| Business Logic in Facade |
Facade makes decisions |
Move logic to domain services |
| Tight Coupling |
Facade depends on concrete classes |
Inject interfaces |
| No Subsystem Access |
Clients can't bypass facade |
Allow direct subsystem use |
| Stateful Facade |
Facade holds state between calls |
Keep facades stateless |
References
For complete PHP templates and examples, see:
references/templates.md — Facade templates for order, notification, report systems
references/examples.md — OrderFacade, NotificationFacade, ReportFacade with unit tests
1---2name: create-facade3description: Generates Facade pattern for PHP 8.4. Creates simplified interface to complex subsystems. Includes unit tests.4metadata:5 source: https://skillmd.com/skills/dykyi-roman/create-facade6---78# Facade Pattern Generator910Creates Facade pattern infrastructure for providing simplified access to complex subsystems.1112## When to Use1314| Scenario | Example |15|----------|---------|16| Complex subsystem simplification | Order facade combining inventory, payment, shipping |17| Multiple service orchestration | Notification facade coordinating email, SMS, push |18| Legacy system wrapping | Facade hiding complex legacy APIs |19| Layered system access | Application layer facade for domain services |2021## Component Characteristics2223### Facade24- Simple unified interface25- Delegates to subsystem classes26- No business logic, only orchestration27- Lives in Application layer2829### Subsystem Classes30- Independent complex operations31- Can be used directly or through facade32- Domain or Infrastructure services3334---3536## Generation Process3738### Step 1: Generate Facade3940**Path:** `src/Application/{BoundedContext}/Facade/`41421. `{Name}Facade.php` — Unified interface to subsystem4344### Step 2: Identify Subsystem Classes (Existing)4546**Paths:** Domain or Infrastructure services47481. Services, Repositories, External APIs492. Multiple components with related functionality5051### Step 3: Generate Tests52531. `{FacadeName}Test.php` — Facade orchestration verification5455---5657## File Placement5859| Component | Path |60|-----------|------|61| Facade | `src/Application/{BoundedContext}/Facade/` |62| Subsystem Classes | `src/Domain/` or `src/Infrastructure/` |63| Unit Tests | `tests/Unit/Application/{BoundedContext}/Facade/` |6465---6667## Naming Conventions6869| Component | Pattern | Example |70|-----------|---------|---------|71| Facade | `{Name}Facade` | `OrderFacade` |72| Test | `{ClassName}Test` | `OrderFacadeTest` |7374---7576## Quick Template Reference7778### Facade7980```php81final readonly class {Name}Facade82{83 public function __construct(84 private {SubsystemA} $subsystemA,85 private {SubsystemB} $subsystemB,86 private {SubsystemC} $subsystemC87 ) {}8889 public function {complexOperation}({params}): {returnType}90 {91 $stepA = $this->subsystemA->{methodA}({params});92 $stepB = $this->subsystemB->{methodB}($stepA);93 $stepC = $this->subsystemC->{methodC}($stepB);9495 return $stepC;96 }97}98```99100---101102## Usage Example103104```php105// Without facade - complex coordination106$inventory = $inventoryService->reserve($productId, $quantity);107$payment = $paymentService->charge($amount, $token);108$shipment = $shippingService->schedule($address, $inventory);109$order = $orderRepository->save(new Order(...));110$notificationService->sendConfirmation($order);111112// With facade - simple call113$order = $orderFacade->placeOrder($command);114```115116---117118## Common Facades119120| Facade | Purpose |121|--------|---------|122| OrderFacade | Coordinate inventory, payment, shipping, notifications |123| NotificationFacade | Send via email, SMS, push, Slack |124| ReportFacade | Generate PDF, Excel, CSV reports |125| UserRegistrationFacade | Validate, create account, send welcome email |126| PaymentFacade | Authorize, charge, record, notify |127| ExportFacade | Fetch data, transform, format, save file |128129---130131## Anti-patterns to Avoid132133| Anti-pattern | Problem | Solution |134|--------------|---------|----------|135| God Facade | Facade does too much | Split into focused facades |136| Business Logic in Facade | Facade makes decisions | Move logic to domain services |137| Tight Coupling | Facade depends on concrete classes | Inject interfaces |138| No Subsystem Access | Clients can't bypass facade | Allow direct subsystem use |139| Stateful Facade | Facade holds state between calls | Keep facades stateless |140141---142143## References144145For complete PHP templates and examples, see:146- `references/templates.md` — Facade templates for order, notification, report systems147- `references/examples.md` — OrderFacade, NotificationFacade, ReportFacade with unit tests