Today, we will be discussing the Chain of Responsibility Pattern. This example decouples the sender and beneficiary of solicitations. This is finished with a chain of articles that can each deal with the demand itself or pass it on to the following item. 3 sections make up the Chain of Responsibility design: sender, recipient, and demand. The sender makes demands. The collector is a chain of at least 1 questions that pick whether to deal with the demand or pass it on. The ask for itself can be a question that typifies all the suitable information, or it could simply be an ordinary capacity approach the beneficiary without any contentions. Senders send the demand to the primary recipient protest in the chain. The sender just thinks about this initial segment of the chain and nothing about alternate recipients. The principal collector either handles the demand or passes it on to the following recipient in the chain. Every recipient just thinks about the following collector in the line.
The ask for will proceed down the line until the point when the demand was dealt with or there are no more recipients to pass it on to, and soon thereafter either a mistake is tossed or nothing happens, contingent upon how you design your chain. For our illustration, we will be making an ATM. The bind will comprise of various estimated dollar greenbacks. When you request some money, the machine begins at the bigger bills and hauls out the same number of those that it needs, at that point proceeds onward to the following littler bill et cetera until we have the majority of the cash or we come up short on bills. This case is intentionally straightforward, on the grounds that that demonstrates the idea all the more plainly without weakening the code with an excessive number of illustration particular usage.