Skip to content

Instantly share code, notes, and snippets.

@sahoosunilkumar
Last active March 18, 2019 05:19
Show Gist options
  • Save sahoosunilkumar/4ec240bc37cb75d3c0537c75590a1fda to your computer and use it in GitHub Desktop.
Save sahoosunilkumar/4ec240bc37cb75d3c0537c75590a1fda to your computer and use it in GitHub Desktop.
Simplifying Payment Using Inheritance
interface IPayment {
void pay();
}
abstract class Payment implements IPayment {
public Payment() {
initialize();
}
protected abstract void initialize();
}
class PaytmPayment extends Payment{
public PaytmPayment() {
super();
}
@Override
protected void initialize() {
// setup with paytm server
System.out.println("paytm server initialized");
}
@Override
public void pay() {
System.out.println("pay by paytm");
}
}
class GooglePayPayment extends Payment {
public GooglePayPayment() {
super();
}
@Override
protected void initialize() {
// setup with paytm server
System.out.println("googlepay server initialized");
}
@Override
public void pay() {
System.out.println("pay by googlepay");
}
}
class PaypalPayment extends Payment {
public PaypalPayment() {
super();
}
@Override
protected void initialize() {
// setup with paytm server
System.out.println("paypal server initialized");
}
@Override
public void pay() {
System.out.println("pay by paypal");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment