SlideShare a Scribd company logo
1 of 13
Download to read offline
GoF
Gang of Four (Design Patterns) in Java
Mina Tafreshi
Software Engineer @ Bol.com
What is a design pattern?
● Design pattern is a general repeatable solution to common problems in
software design.
● A design pattern is not a finished design.
● These patterns are mostly “evolved” rather than “discovered”.
[Note]: Code implementation is your responsibility!
Gang of Four Design Patterns
● Name?
Element of Reusable
Object-Oriented Software.
● By whom?
Erich Gamma, Richard Helm,
Ralph Johnson and John Vlissides
● When?
1994
GoF Design Patterns categories
1. Creational design patterns:
It deal with object creation. They look at ways to solve design issues arising out of creation of objects.
2. Structural design patterns:
Ease the design by identifying a simple way to realize relationships between entities.
3. Behavioral design patterns:
Identify common communication patterns between objects and realize these patterns.
Singleton Design Pattern Ensures only one instance of an object is created.
Factory Design Pattern Creates objects without specifying the exact class
to create.
Abstract Factory Design
Pattern
Allows for the creation of objects without
specifying their concrete type.
Builder Design Pattern Separate the construction of a complex object
from its representation so that the same
construction process can create different
representations.
Prototype Design Pattern Creates a new object from an existing object.
Adapter Design Pattern Convert the interface of a class into another
interface the clients expect.
Bridge Design Pattern Decouple an abstraction from its implementation.
Composite Design Pattern Compose objects into tree structures to represent
part-whole hierarchies.
Decorator Design Pattern Attach additional responsibilities to an object
dynamically.
Facade Design Pattern Facade defines a higher-level interface that makes
the subsystem easier to use.
Flyweight Design Pattern Use sharing to support large numbers of
fine-grained objects efficiently.
Proxy Design Pattern Provide a surrogate or placeholder for another
object to control access to it.
Command Design Pattern Encapsulate a request as an object.
Iterator Design Pattern Accesses the elements of an object sequentially
without exposing its underlying representation
Mediator Design Pattern Allows loose coupling between classes by being the
only class that has detailed knowledge of their
methods.
Memento Design Pattern Provides the ability to restore an object to its previous
state.
Observer Design Pattern publish/subscribe pattern which allows a number of
observer objects to see an event.
State Design Pattern Allow an object to alter its behaviour when its internal
state changes.
Strategy Design Pattern Define a family of algorithms, encapsulate each one,
and make them interchangeable.
Template Method Design Pattern lets subclasses redefine certain steps of an algorithm
without changing the algorithm's structure.
Delegation Pattern where an object expresses certain behavior to the
outside but in reality delegates responsibility for
implementing that behaviour to an associated object.
Singleton Design Pattern:
Ensures only one instance of an object is created
When:
A class in your program should have just a single instance available to all clients.
Why:
The most common reason for this is to control access to some shared resource.
Examples in Java core libraries:
● java.lang.Runtime#getRuntime()
● java.awt.Desktop#getDesktop()
● java.lang.System#getSecurityManager()
Factory Design Pattern:
Creates objects without specifying the exact class to create
When:
You don’t know beforehand the exact types and dependencies of the objects your code should work with.
Why:
The most common reason for this is to control access to some shared resource.
Examples in Java core libraries:
● java.util.Calendar#getInstance()
● java.util.ResourceBundle#getBundle()
● java.text.NumberFormat#getInstance()
● java.nio.charset.Charset#forName()
● java.net.URLStreamHandlerFactory#createURLStreamHandler(String)
● javax.xml.bind.JAXBContext#createMarshaller()
Builder Design Pattern:
Separate the construction of a complex object from its representation
When:
You want your code to be able to create different representations of some objects.
Why:
It lets you build objects step by step, using only those steps that you really need.
Examples in Java core libraries:
● java.lang.StringBuilder#append() (unsynchronized)
● java.lang.StringBuffer#append() (synchronized)
● java.nio.ByteBuffer#put()
( in CharBuffer, ShortBuffer, IntBuffer, LongBuffer, FloatBuffer and DoubleBuffer)
● javax.swing.GroupLayout.Group#addComponent()
● All implementations java.lang.Appendable
Prototype Design Pattern:
Creates a new object from an existing object
When:
Your code shouldn’t depend on the concrete classes of objects that you need to copy
Why:
you want to reduce the number of subclasses that only differ in the way they initialize their respective objects
Examples in Java core libraries:
The Prototype pattern is available in Java out of the box with
a Cloneable interface.
Any class can implement this interface to become cloneable.
● java.lang.Object#clone()
(class should implement the java.lang.Cloneable interface)
Resources:
1. GoF (https://en.wikipedia.org/wiki/Design_Patterns)
2. https://refactoring.guru/design-patterns/
3. Head First Design Patterns (https://www.oreilly.com/library/view/head-first-design/0596007124/)
Email:
mina@tafreshi.me

More Related Content

What's hot

Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
82159587 case-study-on-corba
82159587 case-study-on-corba82159587 case-study-on-corba
82159587 case-study-on-corbahomeworkping3
 
Introduction to Axon FrameWork with CQRS pattern
Introduction to Axon FrameWork with CQRS patternIntroduction to Axon FrameWork with CQRS pattern
Introduction to Axon FrameWork with CQRS patternKnoldus Inc.
 
Class and object_diagram
Class  and object_diagramClass  and object_diagram
Class and object_diagramSadhana28
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General IntroductionAsma CHERIF
 
Gestire La Complessità Con Domain Driven Design
Gestire La Complessità Con Domain Driven DesignGestire La Complessità Con Domain Driven Design
Gestire La Complessità Con Domain Driven DesignAlberto Brandolini
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
From Monolithic to Microservices
From Monolithic to Microservices From Monolithic to Microservices
From Monolithic to Microservices Amazon Web Services
 
Collaboration Diagram
Collaboration DiagramCollaboration Diagram
Collaboration Diagramfahad_uaar
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSeerat Malik
 
Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)Sameer Rathoud
 
Unit 2(advanced class modeling & state diagram)
Unit  2(advanced class modeling & state diagram)Unit  2(advanced class modeling & state diagram)
Unit 2(advanced class modeling & state diagram)Manoj Reddy
 

What's hot (20)

Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
82159587 case-study-on-corba
82159587 case-study-on-corba82159587 case-study-on-corba
82159587 case-study-on-corba
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
DESIGN PATTERNS: Strategy Patterns
DESIGN PATTERNS: Strategy PatternsDESIGN PATTERNS: Strategy Patterns
DESIGN PATTERNS: Strategy Patterns
 
Sequence Diagram
Sequence DiagramSequence Diagram
Sequence Diagram
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 
Introduction to Axon FrameWork with CQRS pattern
Introduction to Axon FrameWork with CQRS patternIntroduction to Axon FrameWork with CQRS pattern
Introduction to Axon FrameWork with CQRS pattern
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
Class and object_diagram
Class  and object_diagramClass  and object_diagram
Class and object_diagram
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Gestire La Complessità Con Domain Driven Design
Gestire La Complessità Con Domain Driven DesignGestire La Complessità Con Domain Driven Design
Gestire La Complessità Con Domain Driven Design
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
From Monolithic to Microservices
From Monolithic to Microservices From Monolithic to Microservices
From Monolithic to Microservices
 
Collaboration Diagram
Collaboration DiagramCollaboration Diagram
Collaboration Diagram
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation Pattern
 
Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)
 
Unit 2(advanced class modeling & state diagram)
Unit  2(advanced class modeling & state diagram)Unit  2(advanced class modeling & state diagram)
Unit 2(advanced class modeling & state diagram)
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 

Similar to Gang of Four in Java

Software design and Architecture.pptx
Software design and Architecture.pptxSoftware design and Architecture.pptx
Software design and Architecture.pptxSHAHZAIBABBAS13
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Luis Valencia
 
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...Anil Sharma
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsJason Townsend, MBA
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
GOF Design pattern with java
GOF Design pattern with javaGOF Design pattern with java
GOF Design pattern with javaRajiv Gupta
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design PatternJaswant Singh
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 
Oops design pattern intro
Oops design pattern intro Oops design pattern intro
Oops design pattern intro anshu_atri
 
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...Simplilearn
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questionsjinaldesailive
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design PatternsLilia Sfaxi
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 

Similar to Gang of Four in Java (20)

Design patterns
Design patternsDesign patterns
Design patterns
 
Software design and Architecture.pptx
Software design and Architecture.pptxSoftware design and Architecture.pptx
Software design and Architecture.pptx
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 
GOF Design pattern with java
GOF Design pattern with javaGOF Design pattern with java
GOF Design pattern with java
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
OOP design patterns
OOP design patternsOOP design patterns
OOP design patterns
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
Oops design pattern intro
Oops design pattern intro Oops design pattern intro
Oops design pattern intro
 
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 

Recently uploaded

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Recently uploaded (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

Gang of Four in Java

  • 1. GoF Gang of Four (Design Patterns) in Java Mina Tafreshi Software Engineer @ Bol.com
  • 2. What is a design pattern? ● Design pattern is a general repeatable solution to common problems in software design. ● A design pattern is not a finished design. ● These patterns are mostly “evolved” rather than “discovered”. [Note]: Code implementation is your responsibility!
  • 3. Gang of Four Design Patterns ● Name? Element of Reusable Object-Oriented Software. ● By whom? Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides ● When? 1994
  • 4. GoF Design Patterns categories 1. Creational design patterns: It deal with object creation. They look at ways to solve design issues arising out of creation of objects. 2. Structural design patterns: Ease the design by identifying a simple way to realize relationships between entities. 3. Behavioral design patterns: Identify common communication patterns between objects and realize these patterns.
  • 5. Singleton Design Pattern Ensures only one instance of an object is created. Factory Design Pattern Creates objects without specifying the exact class to create. Abstract Factory Design Pattern Allows for the creation of objects without specifying their concrete type. Builder Design Pattern Separate the construction of a complex object from its representation so that the same construction process can create different representations. Prototype Design Pattern Creates a new object from an existing object.
  • 6. Adapter Design Pattern Convert the interface of a class into another interface the clients expect. Bridge Design Pattern Decouple an abstraction from its implementation. Composite Design Pattern Compose objects into tree structures to represent part-whole hierarchies. Decorator Design Pattern Attach additional responsibilities to an object dynamically. Facade Design Pattern Facade defines a higher-level interface that makes the subsystem easier to use. Flyweight Design Pattern Use sharing to support large numbers of fine-grained objects efficiently. Proxy Design Pattern Provide a surrogate or placeholder for another object to control access to it.
  • 7. Command Design Pattern Encapsulate a request as an object. Iterator Design Pattern Accesses the elements of an object sequentially without exposing its underlying representation Mediator Design Pattern Allows loose coupling between classes by being the only class that has detailed knowledge of their methods. Memento Design Pattern Provides the ability to restore an object to its previous state. Observer Design Pattern publish/subscribe pattern which allows a number of observer objects to see an event. State Design Pattern Allow an object to alter its behaviour when its internal state changes. Strategy Design Pattern Define a family of algorithms, encapsulate each one, and make them interchangeable. Template Method Design Pattern lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure. Delegation Pattern where an object expresses certain behavior to the outside but in reality delegates responsibility for implementing that behaviour to an associated object.
  • 8. Singleton Design Pattern: Ensures only one instance of an object is created When: A class in your program should have just a single instance available to all clients. Why: The most common reason for this is to control access to some shared resource. Examples in Java core libraries: ● java.lang.Runtime#getRuntime() ● java.awt.Desktop#getDesktop() ● java.lang.System#getSecurityManager()
  • 9. Factory Design Pattern: Creates objects without specifying the exact class to create When: You don’t know beforehand the exact types and dependencies of the objects your code should work with. Why: The most common reason for this is to control access to some shared resource. Examples in Java core libraries: ● java.util.Calendar#getInstance() ● java.util.ResourceBundle#getBundle() ● java.text.NumberFormat#getInstance() ● java.nio.charset.Charset#forName() ● java.net.URLStreamHandlerFactory#createURLStreamHandler(String) ● javax.xml.bind.JAXBContext#createMarshaller()
  • 10. Builder Design Pattern: Separate the construction of a complex object from its representation When: You want your code to be able to create different representations of some objects. Why: It lets you build objects step by step, using only those steps that you really need. Examples in Java core libraries: ● java.lang.StringBuilder#append() (unsynchronized) ● java.lang.StringBuffer#append() (synchronized) ● java.nio.ByteBuffer#put() ( in CharBuffer, ShortBuffer, IntBuffer, LongBuffer, FloatBuffer and DoubleBuffer) ● javax.swing.GroupLayout.Group#addComponent() ● All implementations java.lang.Appendable
  • 11. Prototype Design Pattern: Creates a new object from an existing object When: Your code shouldn’t depend on the concrete classes of objects that you need to copy Why: you want to reduce the number of subclasses that only differ in the way they initialize their respective objects Examples in Java core libraries: The Prototype pattern is available in Java out of the box with a Cloneable interface. Any class can implement this interface to become cloneable. ● java.lang.Object#clone() (class should implement the java.lang.Cloneable interface)
  • 12. Resources: 1. GoF (https://en.wikipedia.org/wiki/Design_Patterns) 2. https://refactoring.guru/design-patterns/ 3. Head First Design Patterns (https://www.oreilly.com/library/view/head-first-design/0596007124/)