Skip to content

Behavioral Patterns

Petar Minev edited this page Apr 4, 2016 · 4 revisions

Behavioral Patterns

#Chain of Responsabillity To consider a more formal example, assume a scenario where you’ve a banking system, and you want to implement some kind of Loan approval. The customer may request a loan, and if it is below a specific amount, the cashier may approve it directly. If it is above the specified amount, he might pass the request to his manager for approval.

So you may use Chain Of Responsibility implementation to hand over the request/command to the correct approver. For an example, consider this implementation of the above Bank account scenario. Our business rule is something like, a cashier can approve the request if the amount is lesser than 1000 $$, otherwise the approval should be passed to the manager. The manager can approve the request if the amount is lesser than 10,000 $$.

We have the following components.

LoanRequest – A concrete request IRequestHandler – Abstract request handler implementation Concrete handlers like Cashier and Manager implement this Has a reference to the successor to pass the request Program – The main driver

resources: http://www.codeproject.com/Articles/283346/Chain-Of-Responsibility-Design-Pattern-in-Csharp-u

##Command

Description: Encapsulate a command request as an object In other words

Intent

Represent an Action as an object

Decouple clients that execute the command from the details and dependencies of the command logic

Enables delayed execution

Clone this wiki locally