인터페이스
public interface IPaymentSystem { Boolean processPayment(); }
인터페이스 구현
public with sharing class DebitCardPaymentSystem implements IPaymentSystem{ public Boolean processPayment() { System.debug('processing a debit card'); return true; } }
public with sharing class ShoppingCart { IPaymentSystem paymentSystem; public ShoppingCart(IPaymentSystem paymentSystem){ this.paymentSystem = paymentSystem; } public void processPayment(){ this.paymentSystem.processPayment(); } public void shipOrder(){ System.debug('Order is Shipped'); } }
IPaymentSystem debit = new DebitCardPaymentSystem(); ShoppingCart cart = new ShoppingCart(debit); debit.processPayment();