SlideShare a Scribd company logo
Strategy
Design Pattern
Alia Hamwi
is a behavioral 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.”
2
3
Navigation app using map:
▰ By car,
▰ By Bus,
▰ Walking.
4
Problem
Navigation app using map:
▰ By car,
▰ By Bus,
▰ Walking.
5
Solution
Pros
▰ swap algorithms used inside an object at runtime.
▰ isolate the implementation details of an algorithm
from the code that uses it.
Pros vs. Cons
6
Cons
▰ If you only have a couple of algorithms and they rarely change,
there’s no real reason to overcomplicate the program with new
classes and interfaces that come along with the pattern.
▰ Clients must be aware of the differences between strategies to be
able to select a proper one.
▰ A lot of modern programming languages lets you implement
different versions of an algorithm inside a set of anonymous
functions. Then you could use these functions exactly as you’d have
used the strategy objects, but without bloating your code with extra
classes and interfaces.
Pros vs. Cons
7
▰ you have a lot of similar classes
that only differ in the way they
execute some behavior.
▰ Use the pattern to isolate the
business logic of a class from the
implementation details of
algorithms.
8
When to use Strategy:
▰ Sorting.
▰ Validation.
▰ Games.
▰ Storing information.
▰ Outputting: We need to output X as a
plain string, but later may be a CSV,
XML, JSON, etc.
9
Real World Example:
▰ Command and Strategy may look similar because you can use both to
parameterize an object with some action. However, they have very
different intents.
▰ State can be considered as an extension of Strategy.. Strategy makes
these objects completely independent and unaware of each other.
However, State doesn’t restrict dependencies between concrete states,
letting them alter the state of the context at will.
10
Strategy with other Design Pattern
11
Code Example:
Template
Design Pattern
is a behavioral design pattern that
▰ defines the skeleton of an algorithm in the
superclass.
▰ lets subclasses override specific steps of
the algorithm without changing its
structure.
13
14
data mining application that analyzes corporate
documents:
▰ PDF,
▰ CSV,
▰ DOC.
15
Problem
data mining application
▰ PDF,
▰ CSV,
▰ DOC.
16
Solution
Pros
▰ let clients override only certain parts of a large
algorithm, making them less affected by changes
that happen to other parts of the algorithm.
▰ You can reduce the duplicate code into a
superclass.
Pros vs. Cons
17
Cons
▰ Some clients may be limited by the provided skeleton of an
algorithm.
Pros vs. Cons
18
▰ you have several classes that
contain almost identical
algorithms with some minor
differences.
▰ let clients extend only particular
steps of an algorithm, but not the
whole algorithm or its structure.
19
When to use Template:
▰ ASP.NET page life cycle: Init, Load,
Validate, Prerender, Render.
▰ Parser.
20
Real World Example:
▰ Template and strategy.
21
Template with other Design Pattern
.
22
Code Example:

More Related Content

What's hot

AWS Tag Management for Cost Allocation
AWS Tag Management for Cost AllocationAWS Tag Management for Cost Allocation
AWS Tag Management for Cost Allocation
Yotascale
 
Deploy, Scale and Manage your Application with AWS Elastic Beanstalk
Deploy, Scale and Manage your Application with AWS Elastic BeanstalkDeploy, Scale and Manage your Application with AWS Elastic Beanstalk
Deploy, Scale and Manage your Application with AWS Elastic Beanstalk
Amazon Web Services
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
Max Claus Nunes
 
Amazon EC2 Masterclass
Amazon EC2 MasterclassAmazon EC2 Masterclass
Amazon EC2 Masterclass
Amazon Web Services
 
AWS & Cloud Foundations
AWS & Cloud FoundationsAWS & Cloud Foundations
AWS & Cloud Foundations
Amazon Web Services
 
AWS ELB
AWS ELBAWS ELB
AWS ELB
Mahesh Raj
 
11 ooad uml-14
11 ooad uml-1411 ooad uml-14
11 ooad uml-14
Niit Care
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
Shakil Ahmed
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
Bharat_Kumawat
 
The Single Responsibility Principle
The Single Responsibility PrincipleThe Single Responsibility Principle
The Single Responsibility Principle
Lars-Erik Kindblad
 
AWS S3 Cost Optimization
AWS S3 Cost OptimizationAWS S3 Cost Optimization
AWS S3 Cost Optimization
Eric Kim
 
Introduction to AWS VPC, Guidelines, and Best Practices
Introduction to AWS VPC, Guidelines, and Best PracticesIntroduction to AWS VPC, Guidelines, and Best Practices
Introduction to AWS VPC, Guidelines, and Best Practices
Gary Silverman
 
Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)
Amazon Web Services
 
Web services SOAP
Web services SOAPWeb services SOAP
Web services SOAP
princeirfancivil
 
Introducing AWS Fargate - AWS Online Tech Talks
Introducing AWS Fargate - AWS Online Tech TalksIntroducing AWS Fargate - AWS Online Tech Talks
Introducing AWS Fargate - AWS Online Tech Talks
Amazon Web Services
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Introduction to Amazon EC2
Introduction to Amazon EC2Introduction to Amazon EC2
Introduction to Amazon EC2
Amazon Web Services
 
2 Object Oriented Programming
2 Object Oriented Programming2 Object Oriented Programming
2 Object Oriented Programming
Praveen M Jigajinni
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
Kumar
 

What's hot (20)

AWS Tag Management for Cost Allocation
AWS Tag Management for Cost AllocationAWS Tag Management for Cost Allocation
AWS Tag Management for Cost Allocation
 
Deploy, Scale and Manage your Application with AWS Elastic Beanstalk
Deploy, Scale and Manage your Application with AWS Elastic BeanstalkDeploy, Scale and Manage your Application with AWS Elastic Beanstalk
Deploy, Scale and Manage your Application with AWS Elastic Beanstalk
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Amazon EC2 Masterclass
Amazon EC2 MasterclassAmazon EC2 Masterclass
Amazon EC2 Masterclass
 
AWS & Cloud Foundations
AWS & Cloud FoundationsAWS & Cloud Foundations
AWS & Cloud Foundations
 
AWS ELB
AWS ELBAWS ELB
AWS ELB
 
11 ooad uml-14
11 ooad uml-1411 ooad uml-14
11 ooad uml-14
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
The Single Responsibility Principle
The Single Responsibility PrincipleThe Single Responsibility Principle
The Single Responsibility Principle
 
AWS S3 Cost Optimization
AWS S3 Cost OptimizationAWS S3 Cost Optimization
AWS S3 Cost Optimization
 
Introduction to AWS VPC, Guidelines, and Best Practices
Introduction to AWS VPC, Guidelines, and Best PracticesIntroduction to AWS VPC, Guidelines, and Best Practices
Introduction to AWS VPC, Guidelines, and Best Practices
 
Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)
 
Web services SOAP
Web services SOAPWeb services SOAP
Web services SOAP
 
Introducing AWS Fargate - AWS Online Tech Talks
Introducing AWS Fargate - AWS Online Tech TalksIntroducing AWS Fargate - AWS Online Tech Talks
Introducing AWS Fargate - AWS Online Tech Talks
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Introduction to Amazon EC2
Introduction to Amazon EC2Introduction to Amazon EC2
Introduction to Amazon EC2
 
2 Object Oriented Programming
2 Object Oriented Programming2 Object Oriented Programming
2 Object Oriented Programming
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 

Similar to Design Pattern (Strategy & Template)

The Ultimate Guide to Ad0 e103 adobe experience manager sites developer
The Ultimate Guide to Ad0 e103 adobe experience manager sites developerThe Ultimate Guide to Ad0 e103 adobe experience manager sites developer
The Ultimate Guide to Ad0 e103 adobe experience manager sites developer
ShoanSharma
 
Design patterns
Design patternsDesign patterns
Design patterns
Ahmed Elharouny
 
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design PatternsNina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
iasaglobal
 
Secret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software SystemsSecret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software Systems
Bart Jonkers
 
Best Practices to Ace ReactJS Web Development!
Best Practices to Ace ReactJS Web Development!Best Practices to Ace ReactJS Web Development!
Best Practices to Ace ReactJS Web Development!
Inexture Solutions
 
Behavioral design patterns presentation
Behavioral design patterns presentationBehavioral design patterns presentation
Behavioral design patterns presentation
Mina Ayoub
 
Angular best practices
Angular best practicesAngular best practices
Angular best practices
Allanki Srinivas
 
Comprehensive Guide to React Development 2022.pptx
Comprehensive Guide to React Development 2022.pptxComprehensive Guide to React Development 2022.pptx
Comprehensive Guide to React Development 2022.pptx
75waytechnologies
 
OOM Unit I - III.pdf
OOM Unit I - III.pdfOOM Unit I - III.pdf
OOM Unit I - III.pdf
ShaikRafikhan1
 
Introduction To Angular.js - SpringPeople
Introduction To Angular.js - SpringPeopleIntroduction To Angular.js - SpringPeople
Introduction To Angular.js - SpringPeople
SpringPeople
 
Software System Engineering - Chapter 9
Software System Engineering - Chapter 9Software System Engineering - Chapter 9
Software System Engineering - Chapter 9
Fadhil Ismail
 
08 hopex v next service fabric
08 hopex v next   service fabric08 hopex v next   service fabric
08 hopex v next service fabric
Michel Bruchet
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
jinaldesailive
 
GraphQL for Native Apps
GraphQL for Native AppsGraphQL for Native Apps
GraphQL for Native Apps
Emanuele Di Saverio
 
How can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfHow can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdf
Mindfire LLC
 
Design patterns
Design patternsDesign patterns
Design patterns
Nahid Mahmudur
 
Non-functional requirements
Non-functional requirements Non-functional requirements
Non-functional requirements
Rohela Raouf
 
Software Design principales
Software Design principalesSoftware Design principales
Software Design principales
ABDEL RAHMAN KARIM
 
Lecture 18 - Model-Driven Service Development
Lecture 18 - Model-Driven Service DevelopmentLecture 18 - Model-Driven Service Development
Lecture 18 - Model-Driven Service Development
phanleson
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
Dmytro Turskyi
 

Similar to Design Pattern (Strategy & Template) (20)

The Ultimate Guide to Ad0 e103 adobe experience manager sites developer
The Ultimate Guide to Ad0 e103 adobe experience manager sites developerThe Ultimate Guide to Ad0 e103 adobe experience manager sites developer
The Ultimate Guide to Ad0 e103 adobe experience manager sites developer
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design PatternsNina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
 
Secret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software SystemsSecret Twists to Efficiently Develop Reactive Software Systems
Secret Twists to Efficiently Develop Reactive Software Systems
 
Best Practices to Ace ReactJS Web Development!
Best Practices to Ace ReactJS Web Development!Best Practices to Ace ReactJS Web Development!
Best Practices to Ace ReactJS Web Development!
 
Behavioral design patterns presentation
Behavioral design patterns presentationBehavioral design patterns presentation
Behavioral design patterns presentation
 
Angular best practices
Angular best practicesAngular best practices
Angular best practices
 
Comprehensive Guide to React Development 2022.pptx
Comprehensive Guide to React Development 2022.pptxComprehensive Guide to React Development 2022.pptx
Comprehensive Guide to React Development 2022.pptx
 
OOM Unit I - III.pdf
OOM Unit I - III.pdfOOM Unit I - III.pdf
OOM Unit I - III.pdf
 
Introduction To Angular.js - SpringPeople
Introduction To Angular.js - SpringPeopleIntroduction To Angular.js - SpringPeople
Introduction To Angular.js - SpringPeople
 
Software System Engineering - Chapter 9
Software System Engineering - Chapter 9Software System Engineering - Chapter 9
Software System Engineering - Chapter 9
 
08 hopex v next service fabric
08 hopex v next   service fabric08 hopex v next   service fabric
08 hopex v next service fabric
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
 
GraphQL for Native Apps
GraphQL for Native AppsGraphQL for Native Apps
GraphQL for Native Apps
 
How can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfHow can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdf
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Non-functional requirements
Non-functional requirements Non-functional requirements
Non-functional requirements
 
Software Design principales
Software Design principalesSoftware Design principales
Software Design principales
 
Lecture 18 - Model-Driven Service Development
Lecture 18 - Model-Driven Service DevelopmentLecture 18 - Model-Driven Service Development
Lecture 18 - Model-Driven Service Development
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
 

More from Alia Hamwi

Teens In AI-Alia.pptx
Teens In AI-Alia.pptxTeens In AI-Alia.pptx
Teens In AI-Alia.pptx
Alia Hamwi
 
Unsupervised Learning
Unsupervised LearningUnsupervised Learning
Unsupervised Learning
Alia Hamwi
 
Supervised learning
Supervised learningSupervised learning
Supervised learning
Alia Hamwi
 
Introduction to natural language processing (NLP)
Introduction to natural language processing (NLP)Introduction to natural language processing (NLP)
Introduction to natural language processing (NLP)
Alia Hamwi
 
Protein Remote Homology Detection
Protein Remote Homology DetectionProtein Remote Homology Detection
Protein Remote Homology Detection
Alia Hamwi
 
Model-driven architecture (MDA)
Model-driven architecture (MDA) Model-driven architecture (MDA)
Model-driven architecture (MDA)
Alia Hamwi
 
Intelligent alert system for the driver
Intelligent alert system for the driverIntelligent alert system for the driver
Intelligent alert system for the driver
Alia Hamwi
 
Social Network Analysis
Social Network AnalysisSocial Network Analysis
Social Network Analysis
Alia Hamwi
 
Optical Neural Network
Optical Neural NetworkOptical Neural Network
Optical Neural Network
Alia Hamwi
 
Human vs machine
Human vs machineHuman vs machine
Human vs machine
Alia Hamwi
 
Introduction To Robotics Challenges
Introduction To Robotics ChallengesIntroduction To Robotics Challenges
Introduction To Robotics Challenges
Alia Hamwi
 
Big Data in Customer Relationship Management (CRM)
Big Data in Customer Relationship Management (CRM)Big Data in Customer Relationship Management (CRM)
Big Data in Customer Relationship Management (CRM)
Alia Hamwi
 

More from Alia Hamwi (12)

Teens In AI-Alia.pptx
Teens In AI-Alia.pptxTeens In AI-Alia.pptx
Teens In AI-Alia.pptx
 
Unsupervised Learning
Unsupervised LearningUnsupervised Learning
Unsupervised Learning
 
Supervised learning
Supervised learningSupervised learning
Supervised learning
 
Introduction to natural language processing (NLP)
Introduction to natural language processing (NLP)Introduction to natural language processing (NLP)
Introduction to natural language processing (NLP)
 
Protein Remote Homology Detection
Protein Remote Homology DetectionProtein Remote Homology Detection
Protein Remote Homology Detection
 
Model-driven architecture (MDA)
Model-driven architecture (MDA) Model-driven architecture (MDA)
Model-driven architecture (MDA)
 
Intelligent alert system for the driver
Intelligent alert system for the driverIntelligent alert system for the driver
Intelligent alert system for the driver
 
Social Network Analysis
Social Network AnalysisSocial Network Analysis
Social Network Analysis
 
Optical Neural Network
Optical Neural NetworkOptical Neural Network
Optical Neural Network
 
Human vs machine
Human vs machineHuman vs machine
Human vs machine
 
Introduction To Robotics Challenges
Introduction To Robotics ChallengesIntroduction To Robotics Challenges
Introduction To Robotics Challenges
 
Big Data in Customer Relationship Management (CRM)
Big Data in Customer Relationship Management (CRM)Big Data in Customer Relationship Management (CRM)
Big Data in Customer Relationship Management (CRM)
 

Recently uploaded

spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 

Recently uploaded (20)

spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 

Design Pattern (Strategy & Template)

  • 2. is a behavioral 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.” 2
  • 3. 3
  • 4. Navigation app using map: ▰ By car, ▰ By Bus, ▰ Walking. 4 Problem
  • 5. Navigation app using map: ▰ By car, ▰ By Bus, ▰ Walking. 5 Solution
  • 6. Pros ▰ swap algorithms used inside an object at runtime. ▰ isolate the implementation details of an algorithm from the code that uses it. Pros vs. Cons 6
  • 7. Cons ▰ If you only have a couple of algorithms and they rarely change, there’s no real reason to overcomplicate the program with new classes and interfaces that come along with the pattern. ▰ Clients must be aware of the differences between strategies to be able to select a proper one. ▰ A lot of modern programming languages lets you implement different versions of an algorithm inside a set of anonymous functions. Then you could use these functions exactly as you’d have used the strategy objects, but without bloating your code with extra classes and interfaces. Pros vs. Cons 7
  • 8. ▰ you have a lot of similar classes that only differ in the way they execute some behavior. ▰ Use the pattern to isolate the business logic of a class from the implementation details of algorithms. 8 When to use Strategy:
  • 9. ▰ Sorting. ▰ Validation. ▰ Games. ▰ Storing information. ▰ Outputting: We need to output X as a plain string, but later may be a CSV, XML, JSON, etc. 9 Real World Example:
  • 10. ▰ Command and Strategy may look similar because you can use both to parameterize an object with some action. However, they have very different intents. ▰ State can be considered as an extension of Strategy.. Strategy makes these objects completely independent and unaware of each other. However, State doesn’t restrict dependencies between concrete states, letting them alter the state of the context at will. 10 Strategy with other Design Pattern
  • 13. is a behavioral design pattern that ▰ defines the skeleton of an algorithm in the superclass. ▰ lets subclasses override specific steps of the algorithm without changing its structure. 13
  • 14. 14
  • 15. data mining application that analyzes corporate documents: ▰ PDF, ▰ CSV, ▰ DOC. 15 Problem
  • 16. data mining application ▰ PDF, ▰ CSV, ▰ DOC. 16 Solution
  • 17. Pros ▰ let clients override only certain parts of a large algorithm, making them less affected by changes that happen to other parts of the algorithm. ▰ You can reduce the duplicate code into a superclass. Pros vs. Cons 17
  • 18. Cons ▰ Some clients may be limited by the provided skeleton of an algorithm. Pros vs. Cons 18
  • 19. ▰ you have several classes that contain almost identical algorithms with some minor differences. ▰ let clients extend only particular steps of an algorithm, but not the whole algorithm or its structure. 19 When to use Template:
  • 20. ▰ ASP.NET page life cycle: Init, Load, Validate, Prerender, Render. ▰ Parser. 20 Real World Example:
  • 21. ▰ Template and strategy. 21 Template with other Design Pattern