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
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: create-facade3description: Generates Facade pattern for PHP 8.4. Creates simplified interface to complex subsystems. Includes unit tests.4---56# Facade Pattern Generator78Creates Facade pattern infrastructure for providing simplified access to complex subsystems.910## When to Use1112| Scenario | Example |13|----------|---------|14| Complex subsystem simplification | Order facade combining inventory, payment, shipping |15| Multiple service orchestration | Notification facade coordinating email, SMS, push |16| Legacy system wrapping | Facade hiding complex legacy APIs |17| Layered system access | Application layer facade for domain services |1819## Component Characteristics2021### Facade22- Simple unified interface23- Delegates to subsystem classes24- No business logic, only orchestration25- Lives in Application layer2627### Subsystem Classes28- Independent complex operations29- Can be used directly or through facade30- Domain or Infrastructure services3132---3334## Generation Process3536### Step 1: Generate Facade3738**Path:** `src/Application/{BoundedContext}/Facade/`39401. `{Name}Facade.php` — Unified interface to subsystem4142### Step 2: Identify Subsystem Classes (Existing)4344**Paths:** Domain or Infrastructure services45461. Services, Repositories, External APIs472. Multiple components with related functionality4849### Step 3: Generate Tests50511. `{FacadeName}Test.php` — Facade orchestration verification5253---5455## File Placement5657| Component | Path |58|-----------|------|59| Facade | `src/Application/{BoundedContext}/Facade/` |60| Subsystem Classes | `src/Domain/` or `src/Infrastructure/` |61| Unit Tests | `tests/Unit/Application/{BoundedContext}/Facade/` |6263---6465## Naming Conventions6667| Component | Pattern | Example |68|-----------|---------|---------|69| Facade | `{Name}Facade` | `OrderFacade` |70| Test | `{ClassName}Test` | `OrderFacadeTest` |7172---7374## Quick Template Reference7576### Facade7778```php79final readonly class {Name}Facade80{81 public function __construct(82 private {SubsystemA} $subsystemA,83 private {SubsystemB} $subsystemB,84 private {SubsystemC} $subsystemC85 ) {}8687 public function {complexOperation}({params}): {returnType}88 {89 $stepA = $this->subsystemA->{methodA}({params});90 $stepB = $this->subsystemB->{methodB}($stepA);91 $stepC = $this->subsystemC->{methodC}($stepB);9293 return $stepC;94 }95}96```9798---99100## Usage Example101102```php103// Without facade - complex coordination104$inventory = $inventoryService->reserve($productId, $quantity);105$payment = $paymentService->charge($amount, $token);106$shipment = $shippingService->schedule($address, $inventory);107$order = $orderRepository->save(new Order(...));108$notificationService->sendConfirmation($order);109110// With facade - simple call111$order = $orderFacade->placeOrder($command);112```113114---115116## Common Facades117118| Facade | Purpose |119|--------|---------|120| OrderFacade | Coordinate inventory, payment, shipping, notifications |121| NotificationFacade | Send via email, SMS, push, Slack |122| ReportFacade | Generate PDF, Excel, CSV reports |123| UserRegistrationFacade | Validate, create account, send welcome email |124| PaymentFacade | Authorize, charge, record, notify |125| ExportFacade | Fetch data, transform, format, save file |126127---128129## Anti-patterns to Avoid130131| Anti-pattern | Problem | Solution |132|--------------|---------|----------|133| God Facade | Facade does too much | Split into focused facades |134| Business Logic in Facade | Facade makes decisions | Move logic to domain services |135| Tight Coupling | Facade depends on concrete classes | Inject interfaces |136| No Subsystem Access | Clients can't bypass facade | Allow direct subsystem use |137| Stateful Facade | Facade holds state between calls | Keep facades stateless |138139---140141## References142143For complete PHP templates and examples, see:144- `references/templates.md` — Facade templates for order, notification, report systems145- `references/examples.md` — OrderFacade, NotificationFacade, ReportFacade with unit tests146147---148> Converted and distributed by [TomeVault](https://tomevault.io/claim/dykyi-roman) — claim your Tome and manage your conversions.149<!-- tomevault:4.0:skill_md:2026-04-11 -->