Description
At the moment the Loan entity contains 7200+ lines. It’s way too complex and became a monster.
Steps to fix the situation
- The business logic needs to be extracted out from this class
- This is an entity, it should only contains the fields, getters, setters and maximum some lightweight methods to manipulate its own state
- At the moment different kind of other classes were injected into this class, all of them need to be extracted into assemblers, services and mapper classes
- transactionProcessorFactory
- loanLifecycleStateMachine
- loanSummaryWrapper
- etc
- Overcomplicated methods and business logic
- Need to refactor and simplify them
- 1 method should do 1 thing
- the enormous amount of conditions and overhead need to be resolved
- Example: handleRepaymentOrRecoveryOrWaiverTransaction
- Need to refactor and simplify them
- We should extract into multiple services / assemblers / mappers as
- Validators
- Creation and modification
- State changes
- Actions on loan
- Disbursement related actions
- Utility actions
- Loan Transaction related actions
- Loan repayment schedule related actions
- Loan balance related actions
- Loan offices related actions
- Loan accounting related actions
- Loan charge related actions
- Interest recalculation related actions
- Loan mapping related actions
- Guarantor related actions
- Loan reschedule related actions
- Delinquency related actions
- Loan mapping actions
- etc
Acceptance criteria
- Job is done, when the Loan entity only contains its fields, setters, getters and basic methods to manipulate its own state
- It does not contain any helpers class anymore
- The business logic extracted into services, assemblers and mappers
- The complex methods and business logic split into smaller well defined pieces which can be easily reused