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

PPTX
PPTX
Strategy Pattern
PPT
Chap05 c
PDF
Uml activity diagram
PPT
Factory Method Pattern
PDF
Factory Design Pattern
PPT
Database design
PPTX
Design pattern-presentation
Strategy Pattern
Chap05 c
Uml activity diagram
Factory Method Pattern
Factory Design Pattern
Database design
Design pattern-presentation

What's hot (20)

PDF
Remote Method Invocation in JAVA
PPTX
Server system architecture
PPT
Class 7 - PHP Object Oriented Programming
PDF
Password cracking
PPT
Hibernate architecture
PPTX
PHP and MySQL.pptx
PPTX
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
PPTX
UML tutorial
PPTX
Ajax
PPT
Oracle archi ppt
PPTX
Ch06 ado.net fundamentals
PPTX
Client Server Architecture in Database Management System
PPT
3 Tier Architecture
PDF
Presentation facade design pattern
PPTX
Distributed datababase Transaction and concurrency control
PPTX
[OOP - Lec 08] Encapsulation (Information Hiding)
PPTX
Database Connectivity in PHP
PPTX
Fundamentals of Data Modeling and Database Design by Dr. Kamal Gulati
PPTX
Introduction to NOSQL databases
ODP
ER Model in DBMS
Remote Method Invocation in JAVA
Server system architecture
Class 7 - PHP Object Oriented Programming
Password cracking
Hibernate architecture
PHP and MySQL.pptx
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
UML tutorial
Ajax
Oracle archi ppt
Ch06 ado.net fundamentals
Client Server Architecture in Database Management System
3 Tier Architecture
Presentation facade design pattern
Distributed datababase Transaction and concurrency control
[OOP - Lec 08] Encapsulation (Information Hiding)
Database Connectivity in PHP
Fundamentals of Data Modeling and Database Design by Dr. Kamal Gulati
Introduction to NOSQL databases
ER Model in DBMS
Ad

Similar to Strategy Design Pattern (11)

PPTX
Strategy
PPTX
Strategy Pattern
PDF
Design Pattern (Strategy & Template)
PPTX
Strategy design pattern
PPTX
PPTX
Lecture 2 ANT.pptx
PDF
An Architecture of Strategy
PPTX
Sse strategy whyville_2011
PPTX
Sse strategy whyville_2011
PPTX
Pm ppt
PPTX
State and Strategy Design Pattern Presentation
Strategy
Strategy Pattern
Design Pattern (Strategy & Template)
Strategy design pattern
Lecture 2 ANT.pptx
An Architecture of Strategy
Sse strategy whyville_2011
Sse strategy whyville_2011
Pm ppt
State and Strategy Design Pattern Presentation
Ad

More from Jyaasa Technologies (20)

PPTX
Incident management with jira
PPTX
Extreme programming practices ( xp )
PPTX
The myth of 'real javascript developer'
PPTX
Microservices
PPTX
Facade pattern in rails
PPTX
Scrum ceromonies
PPTX
An introduction to bitcoin
PPTX
Tor network
PPTX
Collective ownership in agile teams
PPTX
Push notification
PPTX
The Design Thinking Process
PPTX
PPTX
Design sprint
PPTX
Data Flow Diagram
PPTX
OKRs and Actions Overview
PPTX
Active record in rails 5
PPTX
Design Patern::Adaptor pattern
PDF
Association in rails
PDF
Web design layout pattern
Incident management with jira
Extreme programming practices ( xp )
The myth of 'real javascript developer'
Microservices
Facade pattern in rails
Scrum ceromonies
An introduction to bitcoin
Tor network
Collective ownership in agile teams
Push notification
The Design Thinking Process
Design sprint
Data Flow Diagram
OKRs and Actions Overview
Active record in rails 5
Design Patern::Adaptor pattern
Association in rails
Web design layout pattern

Recently uploaded (20)

PPTX
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PDF
DNT Brochure 2025 – ISV Solutions @ D365
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
PPTX
most interesting chapter in the world ppt
PPTX
GSA Content Generator Crack (2025 Latest)
PPTX
Python is a high-level, interpreted programming language
PPTX
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
PDF
AI Guide for Business Growth - Arna Softech
PPTX
CNN LeNet5 Architecture: Neural Networks
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PDF
Guide to Food Delivery App Development.pdf
PDF
BoxLang Dynamic AWS Lambda - Japan Edition
PDF
MCP Security Tutorial - Beginner to Advanced
PDF
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
PDF
Practical Indispensable Project Management Tips for Delivering Successful Exp...
PPTX
Download Adobe Photoshop Crack 2025 Free
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
Trending Python Topics for Data Visualization in 2025
Wondershare Recoverit Full Crack New Version (Latest 2025)
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
DNT Brochure 2025 – ISV Solutions @ D365
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
most interesting chapter in the world ppt
GSA Content Generator Crack (2025 Latest)
Python is a high-level, interpreted programming language
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
AI Guide for Business Growth - Arna Softech
CNN LeNet5 Architecture: Neural Networks
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
Guide to Food Delivery App Development.pdf
BoxLang Dynamic AWS Lambda - Japan Edition
MCP Security Tutorial - Beginner to Advanced
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
Practical Indispensable Project Management Tips for Delivering Successful Exp...
Download Adobe Photoshop Crack 2025 Free

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