Common Design Patterns
Factory, Strategy, Decorator, Adapter, Repository, Unit of Work gibi desenlerin PHP uygulamaları ve hangi durumlarda tercih edileceği. Test edilebilir ve genişletilebilir kod için desen kombinasyonları.
Strategy örneği
<?php
interface TaxStrategy { public function calculate(float $amount): float; }
class VatStrategy implements TaxStrategy { public function calculate(float $amount): float { return $amount * 0.18; } }
class Order {
public function __construct(private TaxStrategy $tax) {}
public function total(float $amount): float { return $amount + $this->tax->calculate($amount); }
}
?>