Skip to content

Instantly share code, notes, and snippets.

@Yerazhas
Last active August 11, 2019 20:09
Show Gist options
  • Select an option

  • Save Yerazhas/bdc5bcc54898ddb8a0da532964cc4c8b to your computer and use it in GitHub Desktop.

Select an option

Save Yerazhas/bdc5bcc54898ddb8a0da532964cc4c8b to your computer and use it in GitHub Desktop.
protocol CapitalStrategy {
func capital(loan: Loan) -> Double
func riskFactor() -> Double
}
extension CapitalStrategy {
func riskFactor() -> Double {
return 0.0
}
}
class RevolverCapitalStrategy: CapitalStrategy {
func capital(loan: Loan) -> Double {
return 250 * riskFactor()
}
}
class TermLoanCapitalStrategy: CapitalStrategy {
func capital(loan: Loan) -> Double {
if loan.expiryDate != nil && loan.maturityDate != nil {
return 10.0 * loan.duration() * riskFactor()
}
if loan.expiryDate != nil && loan.maturityDate == nil {
if loan.getUnusedPercentage() > 1.0 {
return 150.0 * loan.getUnusedPercentage()
} else {
return 200.0 * loan.getUnusedPercentage()
}
}
return 0.0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment