SlideShare a Scribd company logo
1 of 16
Download to read offline
http://jy
aasa.comCopyright 2016. Jyaasa Technologies.
Strategy Pattern
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Ganesh Kunwar
Sr. Software Engineer
Jyaasa Technologies
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
What is Strategy Pattern?
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Ktm Butwal
Taxi Plan Taxi
Ktm.
Airport
Bhairahawa
Airport
Ktm Butwal
Taxi Bus
Kalanki
Ktm Butwal
Taxi Bus BusKalanki
Chitwan
Strategy 1
Strategy 2
Strategy 3
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Wikipedia Definition
the strategy pattern (also known as the policy pattern) is
a software design pattern that enables an algorithm's
behavior to be selected at runtime. The strategy pattern
● defines a family of algorithms,
● encapsulates each algorithm, and
● makes the algorithms interchangeable within that
family.
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
When to Use?
Shopping Mall Example
- Accept customer detail
- Calculate bill amount
- Apply discount based on the day of week
- Monday - High discount (10%)
- Friday - Low discount (5%)
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Where does the discount logic reside?
Inside ShoppingMall class
Or
Outside ShoppingMall class
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Open closed principle
- software entities (classes, modules, functions, etc.) should be open
for extension, but closed for modification
- New discount logic may be applied in future
- Not reusable - Same discount strategy can be use in other shopping
mall
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Separate discount logic from ShoppingMall class
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Context Strategy
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
=> grill = Grill.new(HotDog.new)
=> grill.grilling # => "Grilling the hot dogs!"
=> grill.food = Hamburger.new
=> grill.grilling # => "Grilling the hamburgers!"
=> grill.food = VeggiePatty.new
=> grill.grilling # => "Grilling the veggie patties!"
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
References
- https://dockyard.com/blog/2013/07/25/design-patterns-strategy-pattern
- https://en.wikipedia.org/wiki/Strategy_pattern
- https://sourcemaking.com/design_patterns/strategy
Thank you!
Lets Discuss
github.com/glunwar
@gkunwar1
Copyright 2015. Jyaasa Technologies.Copyright 2016. Jyaasa Technologies.
http://jyaasa.com

More Related Content

What's hot

The State Design Pattern
The State Design PatternThe State Design Pattern
The State Design PatternJosh Candish
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsMichael Heron
 
Presentation facade design pattern
Presentation facade design patternPresentation facade design pattern
Presentation facade design patternBayu Firmawan Paoh
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design PatternsLidan Hifi
 
Visitor Pattern
Visitor PatternVisitor Pattern
Visitor PatternIder Zheng
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern Nirthika Rajendran
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in javasawarkar17
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design PrinciplesAndreas Enbohm
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in javaHitesh Kumar
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design PatternsAnton Keks
 
Overview of UML Diagrams
Overview of UML DiagramsOverview of UML Diagrams
Overview of UML DiagramsManish Kumar
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm propertiesLincoln School
 
Creational pattern
Creational patternCreational pattern
Creational patternHimanshu
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternMudasir Qazi
 
Object Oriented Analysis & Design
Object Oriented Analysis & DesignObject Oriented Analysis & Design
Object Oriented Analysis & DesignMeghaj Mallick
 

What's hot (20)

The State Design Pattern
The State Design PatternThe State Design Pattern
The State Design Pattern
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
 
Presentation facade design pattern
Presentation facade design patternPresentation facade design pattern
Presentation facade design pattern
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design Patterns
 
Visitor Pattern
Visitor PatternVisitor Pattern
Visitor Pattern
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in java
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 
Overview of UML Diagrams
Overview of UML DiagramsOverview of UML Diagrams
Overview of UML Diagrams
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Object Oriented Analysis & Design
Object Oriented Analysis & DesignObject Oriented Analysis & Design
Object Oriented Analysis & Design
 

Similar to Strategy Design Pattern

Welcome your new digital team member. meet your AI infused agile agent
Welcome your new digital team member. meet your AI infused agile agentWelcome your new digital team member. meet your AI infused agile agent
Welcome your new digital team member. meet your AI infused agile agentRaghavendra Meharwade
 
Introduction to GCP (Google Cloud Platform)
Introduction to GCP (Google Cloud Platform)Introduction to GCP (Google Cloud Platform)
Introduction to GCP (Google Cloud Platform)Pulkit Gupta
 
Webinar: Select the Right Web CMS in 2016
Webinar: Select the Right Web CMS in 2016Webinar: Select the Right Web CMS in 2016
Webinar: Select the Right Web CMS in 2016Real Story Group
 
Smart Agile Tools 2020: AI taking it to the future state
Smart Agile Tools 2020: AI taking it to the future stateSmart Agile Tools 2020: AI taking it to the future state
Smart Agile Tools 2020: AI taking it to the future stateRaghavendra Meharwade
 
Machine learning & computer vision
Machine learning & computer visionMachine learning & computer vision
Machine learning & computer visionNetlight Consulting
 
Machine Learning in Computer Vision
Machine Learning in Computer VisionMachine Learning in Computer Vision
Machine Learning in Computer VisionSaksham Gautam
 
Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...
Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...
Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...Amazon Web Services
 
Cwin16 tls-partner-sas new-open_analytics_platform
Cwin16 tls-partner-sas new-open_analytics_platformCwin16 tls-partner-sas new-open_analytics_platform
Cwin16 tls-partner-sas new-open_analytics_platformCapgemini
 
What, Why and How of Governance in RPA
What, Why and How of Governance  in RPAWhat, Why and How of Governance  in RPA
What, Why and How of Governance in RPAMohit Sharma (GAICD)
 
The Future of AI on AWS
The Future of AI on AWSThe Future of AI on AWS
The Future of AI on AWSBoaz Ziniman
 
Just add Imagination
Just add ImaginationJust add Imagination
Just add ImaginationKNIMESlides
 
MLops workshop AWS
MLops workshop AWSMLops workshop AWS
MLops workshop AWSGili Nachum
 
IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...
IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...
IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...IRJET Journal
 
Microservices: The Building Blocks for a Digital Future
Microservices: The Building Blocks for a Digital FutureMicroservices: The Building Blocks for a Digital Future
Microservices: The Building Blocks for a Digital FutureSAP Customer Experience
 
Trends and Best Practices for Implementing SaaS for Your Business
Trends and Best Practices for Implementing SaaS for Your BusinessTrends and Best Practices for Implementing SaaS for Your Business
Trends and Best Practices for Implementing SaaS for Your BusinessCallidus Software
 
Grassroots Kanban – An Evolutionary Approach To Change
Grassroots Kanban – An Evolutionary Approach To ChangeGrassroots Kanban – An Evolutionary Approach To Change
Grassroots Kanban – An Evolutionary Approach To ChangeSynerzip
 

Similar to Strategy Design Pattern (20)

Welcome your new digital team member. meet your AI infused agile agent
Welcome your new digital team member. meet your AI infused agile agentWelcome your new digital team member. meet your AI infused agile agent
Welcome your new digital team member. meet your AI infused agile agent
 
Introduction to GCP (Google Cloud Platform)
Introduction to GCP (Google Cloud Platform)Introduction to GCP (Google Cloud Platform)
Introduction to GCP (Google Cloud Platform)
 
Advances in SAFe DevOps
Advances in SAFe DevOpsAdvances in SAFe DevOps
Advances in SAFe DevOps
 
Webinar: Select the Right Web CMS in 2016
Webinar: Select the Right Web CMS in 2016Webinar: Select the Right Web CMS in 2016
Webinar: Select the Right Web CMS in 2016
 
Smart Agile Tools 2020: AI taking it to the future state
Smart Agile Tools 2020: AI taking it to the future stateSmart Agile Tools 2020: AI taking it to the future state
Smart Agile Tools 2020: AI taking it to the future state
 
Machine Learning: Decision Trees
Machine Learning: Decision TreesMachine Learning: Decision Trees
Machine Learning: Decision Trees
 
Industrial Transformation
Industrial TransformationIndustrial Transformation
Industrial Transformation
 
Analytics Store for Hybrid Cloud
Analytics Store for Hybrid CloudAnalytics Store for Hybrid Cloud
Analytics Store for Hybrid Cloud
 
Machine learning & computer vision
Machine learning & computer visionMachine learning & computer vision
Machine learning & computer vision
 
Machine Learning in Computer Vision
Machine Learning in Computer VisionMachine Learning in Computer Vision
Machine Learning in Computer Vision
 
Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...
Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...
Meet Preston, and Explore Your Digital Twin in Virtual Reality (GPSTEC321) - ...
 
Cwin16 tls-partner-sas new-open_analytics_platform
Cwin16 tls-partner-sas new-open_analytics_platformCwin16 tls-partner-sas new-open_analytics_platform
Cwin16 tls-partner-sas new-open_analytics_platform
 
What, Why and How of Governance in RPA
What, Why and How of Governance  in RPAWhat, Why and How of Governance  in RPA
What, Why and How of Governance in RPA
 
The Future of AI on AWS
The Future of AI on AWSThe Future of AI on AWS
The Future of AI on AWS
 
Just add Imagination
Just add ImaginationJust add Imagination
Just add Imagination
 
MLops workshop AWS
MLops workshop AWSMLops workshop AWS
MLops workshop AWS
 
IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...
IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...
IRJET- Supply Chain Network Design for Plant Location and Selection of Capaci...
 
Microservices: The Building Blocks for a Digital Future
Microservices: The Building Blocks for a Digital FutureMicroservices: The Building Blocks for a Digital Future
Microservices: The Building Blocks for a Digital Future
 
Trends and Best Practices for Implementing SaaS for Your Business
Trends and Best Practices for Implementing SaaS for Your BusinessTrends and Best Practices for Implementing SaaS for Your Business
Trends and Best Practices for Implementing SaaS for Your Business
 
Grassroots Kanban – An Evolutionary Approach To Change
Grassroots Kanban – An Evolutionary Approach To ChangeGrassroots Kanban – An Evolutionary Approach To Change
Grassroots Kanban – An Evolutionary Approach To Change
 

More from Jyaasa Technologies (20)

Incident management with jira
Incident management with jiraIncident management with jira
Incident management with jira
 
Extreme programming practices ( xp )
Extreme programming practices ( xp ) Extreme programming practices ( xp )
Extreme programming practices ( xp )
 
The myth of 'real javascript developer'
The myth of 'real javascript developer'The myth of 'real javascript developer'
The myth of 'real javascript developer'
 
Microservices
MicroservicesMicroservices
Microservices
 
Facade pattern in rails
Facade pattern in railsFacade pattern in rails
Facade pattern in rails
 
Scrum ceromonies
Scrum ceromoniesScrum ceromonies
Scrum ceromonies
 
An introduction to bitcoin
An introduction to bitcoinAn introduction to bitcoin
An introduction to bitcoin
 
Tor network
Tor networkTor network
Tor network
 
Collective ownership in agile teams
Collective ownership in agile teamsCollective ownership in agile teams
Collective ownership in agile teams
 
Push notification
Push notificationPush notification
Push notification
 
The Design Thinking Process
The Design Thinking ProcessThe Design Thinking Process
The Design Thinking Process
 
User story
User storyUser story
User story
 
Design sprint
Design sprintDesign sprint
Design sprint
 
Data Flow Diagram
Data Flow DiagramData Flow Diagram
Data Flow Diagram
 
OKRs and Actions Overview
OKRs and Actions OverviewOKRs and Actions Overview
OKRs and Actions Overview
 
Vue.js
Vue.jsVue.js
Vue.js
 
Active record in rails 5
Active record in rails 5Active record in rails 5
Active record in rails 5
 
Design Patern::Adaptor pattern
Design Patern::Adaptor patternDesign Patern::Adaptor pattern
Design Patern::Adaptor pattern
 
Association in rails
Association in railsAssociation in rails
Association in rails
 
Web design layout pattern
Web design layout patternWeb design layout pattern
Web design layout pattern
 

Recently uploaded

Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 

Recently uploaded (20)

Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 

Strategy Design Pattern

  • 1. http://jy aasa.comCopyright 2016. Jyaasa Technologies. Strategy Pattern
  • 2. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Ganesh Kunwar Sr. Software Engineer Jyaasa Technologies
  • 3. Copyright 2016. Jyaasa Technologies. http://jy aasa.com What is Strategy Pattern?
  • 4. Copyright 2016. Jyaasa Technologies. http://jy aasa.com
  • 5. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Ktm Butwal Taxi Plan Taxi Ktm. Airport Bhairahawa Airport Ktm Butwal Taxi Bus Kalanki Ktm Butwal Taxi Bus BusKalanki Chitwan Strategy 1 Strategy 2 Strategy 3
  • 6. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Wikipedia Definition the strategy pattern (also known as the policy pattern) is a software design pattern that enables an algorithm's behavior to be selected at runtime. The strategy pattern ● defines a family of algorithms, ● encapsulates each algorithm, and ● makes the algorithms interchangeable within that family.
  • 7. Copyright 2016. Jyaasa Technologies. http://jy aasa.com When to Use? Shopping Mall Example - Accept customer detail - Calculate bill amount - Apply discount based on the day of week - Monday - High discount (10%) - Friday - Low discount (5%)
  • 8. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Where does the discount logic reside? Inside ShoppingMall class Or Outside ShoppingMall class
  • 9. Copyright 2016. Jyaasa Technologies. http://jy aasa.com
  • 10. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Open closed principle - software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification - New discount logic may be applied in future - Not reusable - Same discount strategy can be use in other shopping mall
  • 11. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Separate discount logic from ShoppingMall class
  • 12. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Context Strategy
  • 13. Copyright 2016. Jyaasa Technologies. http://jy aasa.com
  • 14. Copyright 2016. Jyaasa Technologies. http://jy aasa.com => grill = Grill.new(HotDog.new) => grill.grilling # => "Grilling the hot dogs!" => grill.food = Hamburger.new => grill.grilling # => "Grilling the hamburgers!" => grill.food = VeggiePatty.new => grill.grilling # => "Grilling the veggie patties!"
  • 15. Copyright 2016. Jyaasa Technologies. http://jy aasa.com References - https://dockyard.com/blog/2013/07/25/design-patterns-strategy-pattern - https://en.wikipedia.org/wiki/Strategy_pattern - https://sourcemaking.com/design_patterns/strategy
  • 16. Thank you! Lets Discuss github.com/glunwar @gkunwar1 Copyright 2015. Jyaasa Technologies.Copyright 2016. Jyaasa Technologies. http://jyaasa.com