Strategy Design Pattern — Exemplified!

public class Textile extends E-kart{   public setDiscount(Discount discount){
discount = discount;
}
public Integer getDiscount(){
discount.getDiscount();
}
}
public class Execute {
public static void main(String[] args){
Textile textile = new Textile();
Discount discount = new ChristmasDiscount(); // It's christmas, let's use Christmas discount pattern textile.setDiscount(discount);
System.out.println(textile.getDiscount());
discount = new BlackFridayDiscount(); // It's Black Friday, let's use a new discount pattern textile.setDiscount(discount);
System.out.println(textile.getDiscount());
}
}

--

--

--

Oracle certified Java Prof | SDE-2 @Paypal

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Finding a technical role that leads to a lasting career

Simple Stock Price Prediction app end_to_end Data Science Project

10 Reasons Why You Should Move To The Cloud

[iOS/Swift] How to read and write custom objects in Firestore

Upload image using rest API in laravel

Linux distributions done

Network on Chip — an Overview | ignitarium.com

Install Gnome and enable root login in Kali Linux 2020.2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Giridharan Shanmugavel

Giridharan Shanmugavel

Oracle certified Java Prof | SDE-2 @Paypal

More from Medium

Design Patterns: Factory Pattern

Design Patterns — Prototype Pattern

Factory Method Design Pattern

Microservices Interview Questions