-
-
Save iyengarajay/57f2176365ecff317e1e3b2d470b25a1 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
import java.util.function.Function; | |
public class StrategyPatternTest { | |
public static void main(String[] args) { | |
Function<Double, Double> normalStrategy = (Double d) -> d; | |
Function<Double, Double> happyHourStrategy = (Double d) -> d * 0.5; | |
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