Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
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 Butw...
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Wikipedia Definition
the strategy pattern (also known as the polic...
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
When to Use?
Shopping Mall Example
- Accept customer detail
- Calc...
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Where does the discount logic reside?
Inside ShoppingMall class
Or...
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
Open closed principle
- software entities (classes, modules, funct...
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 ...
Copyright 2016. Jyaasa Technologies.
http://jy
aasa.com
References
- https://dockyard.com/blog/2013/07/25/design-patterns-...
Thank you!
Lets Discuss
github.com/glunwar
@gkunwar1
Copyright 2015. Jyaasa Technologies.Copyright 2016. Jyaasa Technologi...
Nächste SlideShare
Wird geladen in …5
×

Strategy Design Pattern

636 Aufrufe

Veröffentlicht am

Design patterns: Strategy Pattern
The strategy pattern is a software design pattern that enables an algorithm's behavior to be selected at run time.

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

Strategy Design Pattern

  1. 1. http://jy aasa.comCopyright 2016. Jyaasa Technologies. Strategy Pattern
  2. 2. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Ganesh Kunwar Sr. Software Engineer Jyaasa Technologies
  3. 3. Copyright 2016. Jyaasa Technologies. http://jy aasa.com What is Strategy Pattern?
  4. 4. Copyright 2016. Jyaasa Technologies. http://jy aasa.com
  5. 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. 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. 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. 8. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Where does the discount logic reside? Inside ShoppingMall class Or Outside ShoppingMall class
  9. 9. Copyright 2016. Jyaasa Technologies. http://jy aasa.com
  10. 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. 11. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Separate discount logic from ShoppingMall class
  12. 12. Copyright 2016. Jyaasa Technologies. http://jy aasa.com Context Strategy
  13. 13. Copyright 2016. Jyaasa Technologies. http://jy aasa.com
  14. 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. 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. 16. Thank you! Lets Discuss github.com/glunwar @gkunwar1 Copyright 2015. Jyaasa Technologies.Copyright 2016. Jyaasa Technologies. http://jyaasa.com

×