Skip to content

Instantly share code, notes, and snippets.

@danveloper
Created May 29, 2013 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danveloper/5672395 to your computer and use it in GitHub Desktop.
Save danveloper/5672395 to your computer and use it in GitHub Desktop.
Expansion - "Redefining the Service Layer with Groovy Categories"
class LocalPaymentService implements PaymentService {
// Dependency injected from container
CreditCardPaymentGateway creditCardPaymentGateway
GiftCardPaymentGateway giftCardPaymentGateway
CheckPaymentGateway checkPaymentGateway
EmployeePaymentGateway employeePaymentGateway
public String process(PaymentType paymentType) throws IllegalArgumentException {
if (paymentType instanceof CreditCardPaymentType) {
return doProcess(paymentType)
} else if (paymentType instanceof GiftCardPaymentType) {
return doProcess(paymentType)
} else if (paymentType instanceof CheckPaymentType) {
return doProcess(paymentType)
} else if (paymentType instanceof EmployeePaymentType) {
return doProcess(paymentType)
}
throw new IllegalArgumentException("Supplied payment type is not supported.");
}
private String doProcess(CreditCardPaymentType paymentType) {
// ...
}
private String doProcess(GiftCardPaymentType paymentType) {
// ...
}
private String doProcess(CheckPaymentType paymentType) {
// ...
}
private String doProcess(EmployeePaymentType paymentType) {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment