Search code examples
design-patternschain-of-responsibility

Pipeline design chain of responsibility pattern


I'm designing a pipeline, in its simplest form: a customer applies for a loan, the request goes to the credit score service, after the credit score is calculated, it goes to the credit service with the credit score and the approval or rejection of the loan is calculated there. In this system, would the Chain of Responsibility design pattern be appropriate?The working logic of the system

I'm confused little bit


Solution

  • No. you have one Handler here only which is Credit service that decide based on score calculated from Score Service whether Customer is eligible for the loan or not.in fact i mean the Score Service is not Handler here and it just support the Credit Service (which is handler) with information to handle. But let say there are multiple Credit Services (or credit service with 3 types of loan objects which handle the request) that may handle the loan request base on variety of the score calculated for customer. for example the bank has 3 plans of Loans

    PlanA_Loan require score > 10 for $100000
    PlanB_Loan require score > 7 for $20000
    PlanC_Loan require score > 5 for $10000

    and now you have 3 handlers of A,B,C.
    now we have customer who wants to know the maximum loan he can get. so the credit score service calculates the score let say 8 and call credit service and this scenario happens

    1. Plan A is not satisfied with the score and call the next
    2. Plan B is satisfied with the score and accept and the chain stops here.