Checkout
+ pay(amt)
if/else picks the algorithm
1class Checkout {2 void pay(int amt){3 if (method == CARD) { ... }4 else if (method == PAYPAL) { ... } // add one → edit here5 }6}
State
pay()if/else chain
Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.
Try one problemDefine a family of interchangeable algorithms, put each in its own class, and let the client swap them at runtime — instead of a big if/else picking behaviour.
1class Checkout {2 void pay(int amt){3 if (method == CARD) { ... }4 else if (method == PAYPAL) { ... } // add one → edit here5 }6}
One Checkout class, one pay() method — and inside it a chain of if/else, each branch a whole payment algorithm. Card here, PayPal there, crypto next.