SlideShare a Scribd company logo
1 of 56
Contents
• Rewind the SOLID Principle
• Brief Introduction of Pattern Type
• Command Pattern
 Example
• Visitor Pattern
 Example
• Strategy Pattern
 Example
Problem
• 1-Find out sum of below numbers
45389 + 58942
a) 453263 b)983835
c) 104345 d) 104331
Problem
• 2- Find out the Sum of below numbers:-
( 234000 + 56790)
a) 290799 b) 290720
c) 290755 d) 290790
Problem
3-Find out the sum of below numbers
89436 + 53459
a) 143895 b) 132895
c) 142295 d) 142895
• Given problems if you will see we are trying to implement the
Elimination technique to eliminate the options.
• Use case when we are giving any entrance exam and we have very
less time , we will try to implement this technique
• But the same technique we are not able to implement in third
problem, it is taking time so every pattern have their own use case.
• So Don’t apply technique in every use case
• So the patterns are technique to resolve recurring problem
Always Remember-
• Principle ! = Rule
• Principle Should
• Rule Must
• Principle are use to make the code reusable and increase the
readability
A class should have only one reason to
change
Single Responsibility Principle
Example
Open Close Principle
• software entities should be open for extension, but closed for
modification
Example
Liskov's Substitution Principle(LSP)
• Derived types must be completely substitutable for their base types.
Example
Interface Segregation Principle (ISP)
• Clients should not be forced to depend upon interfaces that they don't use.
Dependency Inversion Principle (DIP)
High-level modules should not depend on low-level modules. Both should depend on abstractions.
Abstractions should not depend on details. Details should depend on abstractions
Design Pattern Type
Contnd…
Command Design Pattern
Example
Command Pattern
• Command Design Pattern is used to encapsulate a request as an
Object[Command]
• and pass to an Invoker,
• wherein Invoker does not knows how to service the request but uses
encapsulated command to perform an action.
Command Pattern Class Diagram
Command Pattern
Command Pattern
Sequence Diagram(Command Pattern)
Demo Example
Command Pattern Class Diagram
Receiver
Concrete Commands
Invoker
Client
Use case –undo and redo or Cut Paste
Command Design Pattern
• Why do we need a “receiver” in the Command design pattern
• We can also Complete Action from Concrete Command:
Answer is
• Pattern Comes from Problems.
• Design Pattern are recurring solutions to common problems of
design!
• Hence As the Problem describe at the end Receiver has to complete
all action
• Like in Hotel Example Cook has to cook all items.
Benefits
• 1- Code Readability by removing if else conditions
• 2- Invoker does not know how to execute the commands.
• 3- Converting the methods into objects.
• 4- We can extend the new commands.(open/close)
• 5- Same code will work for multiple receivers By extending the
Ireceiver
• 6- We can perform Undo and Redo Actions
• 7-Security extension, or interface exposure
• Using a command interface, you can also limit access to your objects,
allowing you to define another level of security
Drawback
• The main disadvantage of the Command pattern is the increase in the
number of classes for each individual command.
• However the command pattern classes are more readable than
creating multiple methods using if else condition.
Visitor Design Pattern
Visitor Pattern Example
Visitor Design Pattern
• If I have to add new operation like Sound() then we have to change
and add new operation all class and interface
• For resolving such kind of problem we use Visitor Pattern.
Visitor Design Pattern
• The Visitor pattern represents an operation to be performed on the
elements of an object structure without changing the classes on
which it operates.
Visitor Class Diagram
Operations
Elements
Visitor
Demo
Shopping Cart example
Strategy Design Pattern
Strategy Pattern Example
Strategy Design Pattern
• The strategy pattern (also known as the policy pattern) is a
behavioral software design pattern that enables an
algorithm's behavior to be selected at runtime. The strategy
patterns
• defines a family of algorithms,
• encapsulates each algorithm, and
• makes the algorithms interchangeable within that family.
Strategy Pattern Class Diagram
Demo
Strategy
Payment Context
Client
Thank u !

More Related Content

Similar to Design pattern

Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
Bill Buchan
 

Similar to Design pattern (20)

PAC 2019 virtual Alexander Podelko
PAC 2019 virtual Alexander Podelko PAC 2019 virtual Alexander Podelko
PAC 2019 virtual Alexander Podelko
 
"A Framework for Developing Trading Models Based on Machine Learning" by Kris...
"A Framework for Developing Trading Models Based on Machine Learning" by Kris..."A Framework for Developing Trading Models Based on Machine Learning" by Kris...
"A Framework for Developing Trading Models Based on Machine Learning" by Kris...
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
 
DESIGN PATTERN.pptx
DESIGN PATTERN.pptxDESIGN PATTERN.pptx
DESIGN PATTERN.pptx
 
DESIGN PATTERN.pptx
DESIGN PATTERN.pptxDESIGN PATTERN.pptx
DESIGN PATTERN.pptx
 
Episode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex TriggersEpisode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex Triggers
 
Solving Large Scale Optimization Problems using CPLEX Optimization Studio
Solving Large Scale Optimization Problems using CPLEX Optimization StudioSolving Large Scale Optimization Problems using CPLEX Optimization Studio
Solving Large Scale Optimization Problems using CPLEX Optimization Studio
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and Beyond
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing Software
 
31 days Refactoring
31 days Refactoring31 days Refactoring
31 days Refactoring
 
Design pattern
Design patternDesign pattern
Design pattern
 
MLCC Schedule #1
MLCC Schedule #1MLCC Schedule #1
MLCC Schedule #1
 
Clean code
Clean codeClean code
Clean code
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 
Commonly used design patterns
Commonly used design patternsCommonly used design patterns
Commonly used design patterns
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Dss6 7
Dss6 7Dss6 7
Dss6 7
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
Clean Code
Clean CodeClean Code
Clean Code
 
Lecture3.se.pptx
Lecture3.se.pptxLecture3.se.pptx
Lecture3.se.pptx
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 

Design pattern