Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dependency Injection in Apex
public interface PaymentInterface{
String processPayment();
}
public class PaypalPaymentService implements PaymentInterface{
public String processPayment(){
// 1. Connect to payment processor
// 2. ???
// 3. Profit!
return 'Paypal successfully processed your payment!';
}
}
public class ServiceFactory{
public static PaymentInterface getPaymentInterface(){
return (PaymentInterface)Type.forName(InheritenceSettings__c.getInstance().PaymentService__c).newInstance();
}
}
public class StripePaymentService implements PaymentInterface{
public String processPayment(){
// 1. Connect to payment processor
// 2. ???
// 3. Profit!
return 'Stripe successfully processed your payment!';
}
}
@jessealtman

This comment has been minimized.

Copy link
Owner Author

commented Apr 19, 2014

This code is from my blog article Dependency Injection in Apex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.