Last active
March 18, 2019 05:19
-
-
Save sahoosunilkumar/4ec240bc37cb75d3c0537c75590a1fda to your computer and use it in GitHub Desktop.
Simplifying Payment Using Inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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