Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fragility - "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) {
if ("CA".equalsIgnoreCase(paymentType.getPayee().getBillingAddress().getState())) {
return doCaliforniaCreditProcessing(paymentType)
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.");
// … [snip] … implementation methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment