Skip to content

Pricing-policy architecture comparison

Compare conditional.php with strategies.php.

The conditional is preferable while policy is small, stable and changed together. Strategies become useful when algorithms vary independently, are selected at runtime, or carry meaningful isolated behavior. More classes are not evidence of better SOLID compliance.

Ask:

  • What is the actual axis of change?
  • Who selects the policy?
  • Does extraction protect an invariant or only distribute a switch statement?
  • Can a closure or enum method express the variation more clearly?