SlideShare a Scribd company logo
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
Design pattern
Command Pattern
Sequence Diagram(Command Pattern)
Demo Example
Command Pattern Class Diagram
Design pattern
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

PPTX
Wholesaler of Gift items in bulk
PDF
Java Design Patterns Tutorial | Edureka
PPTX
L03 Design Patterns
PDF
The maze of Design Patterns & SOLID Principles
PDF
Design Patterns
PPTX
Design Patterns- Course for students .pptx
PPT
Design patterns
PPTX
Applying design patterns
Wholesaler of Gift items in bulk
Java Design Patterns Tutorial | Edureka
L03 Design Patterns
The maze of Design Patterns & SOLID Principles
Design Patterns
Design Patterns- Course for students .pptx
Design patterns
Applying design patterns

Similar to Design pattern (20)

PPTX
Sofwear deasign and need of design pattern
PPT
12266422.ppt
 
PPTX
Design Principles to design Patterns
PDF
Design Patterns Java programming language.pdf
PPTX
Let us understand design pattern
PPTX
Segue to design patterns
PPT
Design patterns
DOCX
Design pattern application
PDF
Java Design Patterns Interview Questions PDF By ScholarHat
PPTX
Design patterns
PDF
software engineering Design Patterns.pdf
PPTX
Software design and Architecture.pptx
PPTX
Design patterns Structural
PPTX
Behavioral pattern By:-Priyanka Pradhan
PPTX
UNIT IV DESIGN PATTERNS.pptx
PPTX
Some Cool Design Patterns, Practices, and Principles
PPTX
Design Pattern - Introduction
PPTX
Introduction to Design Patterns
PDF
Java-Design-Patterns.pdf
PPTX
Gof design patterns
Sofwear deasign and need of design pattern
12266422.ppt
 
Design Principles to design Patterns
Design Patterns Java programming language.pdf
Let us understand design pattern
Segue to design patterns
Design patterns
Design pattern application
Java Design Patterns Interview Questions PDF By ScholarHat
Design patterns
software engineering Design Patterns.pdf
Software design and Architecture.pptx
Design patterns Structural
Behavioral pattern By:-Priyanka Pradhan
UNIT IV DESIGN PATTERNS.pptx
Some Cool Design Patterns, Practices, and Principles
Design Pattern - Introduction
Introduction to Design Patterns
Java-Design-Patterns.pdf
Gof design patterns
Ad

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
KodekX | Application Modernization Development
 
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
 
PPTX
Spectroscopy.pptx food analysis technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KodekX | Application Modernization Development
 
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks
NewMind AI Weekly Chronicles - August'25 Week I
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
 
Spectroscopy.pptx food analysis technology
sap open course for s4hana steps from ECC to s4
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Teaching material agriculture food technology
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Diabetes mellitus diagnosis method based random forest with bat algorithm
Ad

Design pattern