-
-
Save iyengarajay/0a9c08bb45fd1f614769bfab9843d2ae to your computer and use it in GitHub Desktop.
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
public class StrategyPatternTest { | |
public static void main(String[] args) { | |
Function<Double, Double> normalStrategy = BillingStrategy::getNormalStrategy; | |
Function<Double, Double> happyHourStrategy = BillingStrategy::getHappyHourStrategy; | |
Customer firstCustomer = new Customer(normalStrategy); | |
// Normal billing | |
firstCustomer.add(1.0, 1); | |
// Start Happy Hour | |
firstCustomer.setStrategy(happyHourStrategy); | |
firstCustomer.add(1.0, 2); | |
// New Customer | |
Customer secondCustomer = new Customer(happyHourStrategy); | |
secondCustomer.add(0.8, 1); | |
// The Customer pays | |
firstCustomer.printBill(); | |
// End Happy Hour | |
secondCustomer.setStrategy(normalStrategy); | |
secondCustomer.add(1.3, 2); | |
secondCustomer.add(2.5, 1); | |
secondCustomer.printBill(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment