// Avoid coupling the sender of a request to its receiver by giving more than one // object a chance to handle the request. // ارسال کننده و دریافت کننده درخواست جدا شوند public static void Main(string[] _) { const int price = 299; var bank = new Bank(); var payPal = new PayPal(); var bitcoin = new Bitcoin(); bank.SetNext(payPal); payPal.SetNext(bitcoin); bank.Pay(price); Console.ReadKey(); }
static void Main() { // Let's prepare a chain like below // $bank->$paypal->$bitcoin // // First priority bank // If bank can't pay then paypal // If paypal can't pay then bit coin var bank = new Bank(3.50m); var payPal = new PayPal(27.50m); var bitcoin = new Bitcoin(1000000m); bank.SetNext(payPal); payPal.SetNext(bitcoin); bank.Pay(1020m); }