-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpenseHandler.cs
More file actions
38 lines (31 loc) · 996 Bytes
/
ExpenseHandler.cs
File metadata and controls
38 lines (31 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
namespace chain.of.responsibility.pattern
{
public interface IExpenseHandler
{
ApprovalResponse Approve(IExpenseReport expenseReport);
void RegisterNext(IExpenseHandler next);
}
public class ExpenseHandler : IExpenseHandler
{
private readonly IExpenseApprover _approver;
private IExpenseHandler _next;
public ExpenseHandler(IExpenseApprover expenseApprover)
{
_approver = expenseApprover;
_next = EndOfChainExpenseHandler.Instance;
}
public ApprovalResponse Approve(IExpenseReport expenseReport)
{
ApprovalResponse response = _approver.ApproveExpense(expenseReport);
if (response == ApprovalResponse.BeyondApprovalLimit)
{
return _next.Approve(expenseReport);
}
return response;
}
public void RegisterNext(IExpenseHandler next)
{
_next = next;
}
}
}