Skip to content

Latest commit

 

History

History
42 lines (27 loc) · 1.14 KB

File metadata and controls

42 lines (27 loc) · 1.14 KB

Chain Of Responsibility

Description:

As the name suggests, the chain of responsibility pattern creates a chain of receiver objects for a request. This pattern decouples sender and receiver of a request based on type of request. This pattern comes under behavioral patterns.

In this pattern, normally each receiver contains reference to another receiver. If one object cannot handle the request then it passes the same to the next receiver and so on.

Implementation:

In this example we have different roles, each having a fixed purchasing limit and a successor. Every time a user in a role receives a purchase request that exceeds his or her limit, the request is passed to his or her successor.

The PurchasePower abstract class with the abstract method processRequest.

Files:

AbstractPurchasePower

ManagerPurchasePower

DirectorPurchasePower

PresidentPurchasePower

PurchaseRequest

Demo

Running tests

npm test