@Test public void shouldUseMonthlyCalculator() { LoanDurationInAccountingYearsCalculator loanDurationCalculator = loanDurationCalculatorFactory.create(RecurrenceType.MONTHLY); assertThat(loanDurationCalculator, is(instanceOf(LoanDurationInAccountingYearsCalculatorFactoryForMonthlyRecurrence.class))); }
public LoanDurationInAccountingYearsCalculator create(RecurrenceType recurrenceType) { switch (recurrenceType) { case MONTHLY: return new LoanDurationInAccountingYearsCalculatorFactoryForMonthlyRecurrence(); case WEEKLY: return new LoanDurationInAccountingYearsCalculatorFactoryForWeeklyRecurrence(); case DAILY: return new LoanDurationInAccountingYearsCalculatorFactoryForDailyRecurrence(); default: throw new BusinessRuleException(AccountConstants.NOT_SUPPORTED_DURATION_TYPE); } }
LoanDurationInAccountingYearsCalculatorFactory { public LoanDurationInAccountingYearsCalculator create(RecurrenceType recurrenceType) { switch (recurrenceType) { case MONTHLY: return new LoanDurationInAccountingYearsCalculatorFactoryForMonthlyRecurrence(); case WEEKLY: return new LoanDurationInAccountingYearsCalculatorFactoryForWeeklyRecurrence(); case DAILY: return new LoanDurationInAccountingYearsCalculatorFactoryForDailyRecurrence(); default: throw new BusinessRuleException(AccountConstants.NOT_SUPPORTED_DURATION_TYPE); } } }
LoanDurationInAccountingYearsCalculatorFactory { public LoanDurationInAccountingYearsCalculator create(RecurrenceType recurrenceType) { switch (recurrenceType) { case MONTHLY: return new LoanDurationInAccountingYearsCalculatorFactoryForMonthlyRecurrence(); case WEEKLY: return new LoanDurationInAccountingYearsCalculatorFactoryForWeeklyRecurrence(); case DAILY: return new LoanDurationInAccountingYearsCalculatorFactoryForDailyRecurrence(); default: throw new BusinessRuleException(AccountConstants.NOT_SUPPORTED_DURATION_TYPE); } }  }
LoanDurationInAccountingYearsCalculatorFactory { public LoanDurationInAccountingYearsCalculator create(RecurrenceType recurrenceType) { switch (recurrenceType) { case MONTHLY: return new LoanDurationInAccountingYearsCalculatorFactoryForMonthlyRecurrence(); case WEEKLY: return new LoanDurationInAccountingYearsCalculatorFactoryForWeeklyRecurrence(); case DAILY: return new LoanDurationInAccountingYearsCalculatorFactoryForDailyRecurrence(); default: throw new BusinessRuleException(AccountConstants.NOT_SUPPORTED_DURATION_TYPE); } }  LoanDurationInAccountingYearsCalculator create(RecurrenceType recurrenceType); }
LoanDurationInAccountingYearsCalculatorFactory { public LoanDurationInAccountingYearsCalculator create(RecurrenceType recurrenceType) { switch (recurrenceType) { case MONTHLY: return new LoanDurationInAccountingYearsCalculatorFactoryForMonthlyRecurrence(); case WEEKLY: return new LoanDurationInAccountingYearsCalculatorFactoryForWeeklyRecurrence(); case DAILY: return new LoanDurationInAccountingYearsCalculatorFactoryForDailyRecurrence(); default: throw new BusinessRuleException(AccountConstants.NOT_SUPPORTED_DURATION_TYPE); } }  LoanDurationInAccountingYearsCalculator create(RecurrenceType recurrenceType);  }