SlideShare une entreprise Scribd logo
1  sur  25
Design Pattern
Introduction
Singleton & Abstract Factory Design
Pattern
-ParamiSoft Systems Pvt. Ltd.
Agenda
• Introduction to Design Patterns
o What is a Design Pattern
o Why Study Design Patterns
o History of Design Patterns
o The Gang of Four
• The Singleton Pattern
o Introduction
o Logger Example
o Lazy Instantiation
o Limitations
Abstract Factory Pattern
o Abstract Factory in real life
o Example
o Real life vs Java Object
o Limitations
-ParamiSoft Systems Pvt. Ltd.
What is a Design Pattern?
• A problem that someone has already solved.
• A model or design to use as a guide
• More formally: “A proven solution to a common problem
in a specified context."
Real World Examples
• Blueprint for a house
• Manufacturing
-ParamiSoft Systems Pvt. Ltd.
Why Study Design Patterns?
• Provides software developers a toolkit for handling
problems that have already been solved.
• Provides a vocabulary that can be used amongst
software developers.
o The Pattern Name itself helps establish a vocabulary
• Helps you think about how to solve a software problem.
-ParamiSoft Systems Pvt. Ltd.
History of Design Patterns
• Christopher Alexander (Civil Engineer) in 1977 wrote
o “Each pattern describes a problem which occurs over and over again in our
environment, and then describes the core of the solution to that problem, in such
a way that you can use this solution a million times over, without ever doing it the
same way twice.”
• Each pattern has the same elements
o Pattern Name – helps develop a catalog of common problems
o Problem – describes when to apply the pattern. Describes problem and its
context.
o Solution – Elements that make up the design, their
relationships, responsibilities, and collaborations.
o Consequences – Results and trade-offs of applying the pattern
-ParamiSoft Systems Pvt. Ltd.
The Gang of Four
• Defines a Catalog of different design patterns.
• Three different types
o Creational – “creating objects in a manner suitable for the situation”
o Structural – “ease the design by identifying a simple way to realize relationships
between entities”
o behavioural– “common communication patterns between objects”
-ParamiSoft Systems Pvt. Ltd.
The Gang of Four: Pattern Catalog
Creational
Abstract Factory
Builder
Factory Method
Prototype
Singleton
Structural
Adapter
Bridge
Composite
Decorator
Façade
Flyweight
Proxy
Behavioral
Chain of Responsibility
Command
Interpreter
Iterator
Mediator
Memento
Observer
State
Strategy
Template Method
Visitor
Patterns in red we will
discuss in this presentation
-ParamiSoft Systems Pvt. Ltd.
Singleton Pattern
-ParamiSoft Systems Pvt. Ltd.
Singleton
• Definition: “The Singleton Pattern ensures a class has
only one instance, and provides a global point of access
to it.”
• Best Uses
o Logging
o Caches
o Registry Settings
o Access External Resources
• Printer
• Device Driver
• Database
-ParamiSoft Systems Pvt. Ltd.
Example: Logger
What is wrong with this code?
public class Logger
{
public Logger() { }
public void LogMessage() {
//Open File "log.txt"
//Write Message
//Close File
}
}
-ParamiSoft Systems Pvt. Ltd.
Example: Logger
• Since there is an external Shared Resource
(“log.txt”), we want to closely control how we
communicate with it.
• We shouldn’t have to create the Logger class every time
we want to access this Shared Resource. Is there any
reason to?
• We need ONE.
-ParamiSoft Systems Pvt. Ltd.
Logger – as a Singleton
public class Logger
{
private Logger{}
private static Logger uniqueInstance;
public static Logger getInstance()
{
if (uniqueInstance == null)
uniqueInstance = new Logger();
return uniqueInstance;
}
}
Note the
parameterless
constructor
-ParamiSoft Systems Pvt. Ltd.
Lazy Instantiation
• Objects are only created when it is needed
• Helps control that we’ve created the Singleton just once.
• If it is resource intensive to set up, we want to do it once.
-ParamiSoft Systems Pvt. Ltd.
Singleton Consequences
• Controlled access to sole instance facilitates strict
control over when and how the clients access it
• The singleton patter is improvement over global
variables.
• It is easy to configure an instance of the application that
extends the functionality of singleton at run-time
• More flexible than class operations
-ParamiSoft Systems Pvt. Ltd.
Singleton Limitations
• The main limitation of the singleton pattern is that is
permits the creation of only one instance of the
class, while most practical applications require multiple
instances to be initialized.
• Furthermore, in case of singleton, the system threads
fight to access the single instance thereby degrading the
performance of the applications.
-ParamiSoft Systems Pvt. Ltd.
Abstract Factory Pattern
-ParamiSoft Systems Pvt. Ltd.
Abstract Factory Pattern is similar to Sub Contracting in real world.
Basically delegating the creation of Objects to expert Factories
-----------------------------------
Orders in a restaurant are received by a Kitchen.
Then are assigned to Special Chefs like
Chinese, Indian, Continental.
Abstract Factory Pattern is a Creational Pattern.
Similar to Factory Pattern it is Object Creation without exposing “HOW” ?
Abstract Factory Pattern in Real Life
-ParamiSoft Systems Pvt. Ltd.
Abstract Factory Pattern in Java
-ParamiSoft Systems Pvt. Ltd.
Factory
Kitchen
Real Life vs Java Object
-ParamiSoft Systems Pvt. Ltd.
1 Orders a Dish from Menu
2
Receives the Order
Creates the Dish
4 Delivers the Dish
3 Outsources to Chef
How Factory Pattern works in Real Life ?
KitchenFactory factory = new KitchenFactory();
Food dosa = factory.getFood("Dosa");
dosa.print();
Food noodles = factory.getFood("Noodles");
noodles.print();
public Food getFood(String name) {
if (name.equals("Dosa")) {
IndianFactory factory = new IndianFactory();
return factory.getFood(name);
} else if (name.equals("Noodles")) {
ChineseFactory factory = new ChineseFactory();
return factory.getFood(name);
}
Return null;}
1
4
Food
Dosa Noodles
2
3
Create food from Respective Factory Class
How Factory Pattern works in Java?
-ParamiSoft Systems Pvt. Ltd.
Abstract Factory Consequences
• Isolate concrete classes.
• Make exchanging product families easy.
• Promote consistency among products
-ParamiSoft Systems Pvt. Ltd.
Abstract Factory Limitation
• Supporting new kinds of products is difficult.
-ParamiSoft Systems Pvt. Ltd.
References
Links
o http://en.wikipedia.org/wiki/Design_pattern
o http://sourcemaking.com/design_patterns
Links
o Design Patterns in Ruby – Russ Olsen
o Head First Design Patterns – Elisabeth Freeman, Eric Freeman, Bert Bates and
Kathy Sierra
-ParamiSoft Systems Pvt. Ltd.
If(Questions)
{
Ask;
}
else
{
Thank you;
}
-ParamiSoft Systems Pvt. Ltd.

Contenu connexe

Tendances

Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Dependency injection presentation
Dependency injection presentationDependency injection presentation
Dependency injection presentationAhasanul Kalam Akib
 
Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade PatternMudasir Qazi
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan GoleChetan Gole
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonJonathan Simon
 
Design Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract FactoryDesign Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract FactoryGuillermo Daniel Salazar
 
Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Sameer Rathoud
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General IntroductionAsma CHERIF
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
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
 

Tendances (20)

Facade pattern
Facade patternFacade pattern
Facade pattern
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Dependency injection presentation
Dependency injection presentationDependency injection presentation
Dependency injection presentation
 
Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade Pattern
 
Facade Pattern
Facade PatternFacade Pattern
Facade Pattern
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
Design Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract FactoryDesign Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract Factory
 
Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design 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)
 

Similaire à Design pattern (Abstract Factory & Singleton)

Automating Ensemble Monitoring and Reporting
Automating Ensemble Monitoring and ReportingAutomating Ensemble Monitoring and Reporting
Automating Ensemble Monitoring and ReportingInterSystems Corporation
 
Fundamental Design Patterns.pptx
Fundamental Design Patterns.pptxFundamental Design Patterns.pptx
Fundamental Design Patterns.pptxJUNSHIN8
 
33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmodwalkmod
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...SQALab
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptxSachin Patidar
 
Beyond design patterns phpnw14
Beyond design patterns   phpnw14Beyond design patterns   phpnw14
Beyond design patterns phpnw14Anthony Ferrara
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design PatternsSteven Smith
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design PatternsPham Huy Tung
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010Clay Helberg
 
Structural patterns
Structural patternsStructural patterns
Structural patternsHimanshu
 
walkmod - JUG talk
walkmod - JUG talkwalkmod - JUG talk
walkmod - JUG talkwalkmod
 
Chaos Engineering Talk at DevOps Days Austin
Chaos Engineering Talk at DevOps Days AustinChaos Engineering Talk at DevOps Days Austin
Chaos Engineering Talk at DevOps Days Austinmatthewbrahms
 
Why Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringWhy Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringProtelo, Inc.
 
Switch! Recommending Artifacts Needed Next Based on Personal and Shared Context
Switch! Recommending Artifacts Needed Next Based on Personal and Shared ContextSwitch! Recommending Artifacts Needed Next Based on Personal and Shared Context
Switch! Recommending Artifacts Needed Next Based on Personal and Shared Contextalexandersahm
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad WoodOrtus Solutions, Corp
 
note2_DesignPatterns (1).pptx
note2_DesignPatterns (1).pptxnote2_DesignPatterns (1).pptx
note2_DesignPatterns (1).pptxReemaAsker1
 

Similaire à Design pattern (Abstract Factory & Singleton) (20)

Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
Automating Ensemble Monitoring and Reporting
Automating Ensemble Monitoring and ReportingAutomating Ensemble Monitoring and Reporting
Automating Ensemble Monitoring and Reporting
 
Fundamental Design Patterns.pptx
Fundamental Design Patterns.pptxFundamental Design Patterns.pptx
Fundamental Design Patterns.pptx
 
33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
 
Beyond design patterns phpnw14
Beyond design patterns   phpnw14Beyond design patterns   phpnw14
Beyond design patterns phpnw14
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design Patterns
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design Patterns
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
Structural patterns
Structural patternsStructural patterns
Structural patterns
 
walkmod - JUG talk
walkmod - JUG talkwalkmod - JUG talk
walkmod - JUG talk
 
Chaos Engineering Talk at DevOps Days Austin
Chaos Engineering Talk at DevOps Days AustinChaos Engineering Talk at DevOps Days Austin
Chaos Engineering Talk at DevOps Days Austin
 
Why Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringWhy Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software Engineering
 
Switch! Recommending Artifacts Needed Next Based on Personal and Shared Context
Switch! Recommending Artifacts Needed Next Based on Personal and Shared ContextSwitch! Recommending Artifacts Needed Next Based on Personal and Shared Context
Switch! Recommending Artifacts Needed Next Based on Personal and Shared Context
 
Design patterns
Design patternsDesign patterns
Design patterns
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Wood
 
Feedback Loops
Feedback LoopsFeedback Loops
Feedback Loops
 
note2_DesignPatterns (1).pptx
note2_DesignPatterns (1).pptxnote2_DesignPatterns (1).pptx
note2_DesignPatterns (1).pptx
 

Plus de paramisoft

Go language presentation
Go language presentationGo language presentation
Go language presentationparamisoft
 
Ruby on Rails Introduction
Ruby on Rails IntroductionRuby on Rails Introduction
Ruby on Rails Introductionparamisoft
 
Introduction To Backbone JS
Introduction To Backbone JSIntroduction To Backbone JS
Introduction To Backbone JSparamisoft
 
Git essentials
Git essentials Git essentials
Git essentials paramisoft
 
iOS development introduction
iOS development introduction iOS development introduction
iOS development introduction paramisoft
 
Introduction to HAML
Introduction to  HAML Introduction to  HAML
Introduction to HAML paramisoft
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder paramisoft
 
ParamiSoft Systems Pvt. Ltd. Profile
ParamiSoft Systems Pvt. Ltd. ProfileParamiSoft Systems Pvt. Ltd. Profile
ParamiSoft Systems Pvt. Ltd. Profileparamisoft
 
Garden City Ruby Conference - lightening talk
Garden City Ruby Conference - lightening talkGarden City Ruby Conference - lightening talk
Garden City Ruby Conference - lightening talkparamisoft
 

Plus de paramisoft (9)

Go language presentation
Go language presentationGo language presentation
Go language presentation
 
Ruby on Rails Introduction
Ruby on Rails IntroductionRuby on Rails Introduction
Ruby on Rails Introduction
 
Introduction To Backbone JS
Introduction To Backbone JSIntroduction To Backbone JS
Introduction To Backbone JS
 
Git essentials
Git essentials Git essentials
Git essentials
 
iOS development introduction
iOS development introduction iOS development introduction
iOS development introduction
 
Introduction to HAML
Introduction to  HAML Introduction to  HAML
Introduction to HAML
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder
 
ParamiSoft Systems Pvt. Ltd. Profile
ParamiSoft Systems Pvt. Ltd. ProfileParamiSoft Systems Pvt. Ltd. Profile
ParamiSoft Systems Pvt. Ltd. Profile
 
Garden City Ruby Conference - lightening talk
Garden City Ruby Conference - lightening talkGarden City Ruby Conference - lightening talk
Garden City Ruby Conference - lightening talk
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Dernier (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Design pattern (Abstract Factory & Singleton)

  • 1. Design Pattern Introduction Singleton & Abstract Factory Design Pattern -ParamiSoft Systems Pvt. Ltd.
  • 2. Agenda • Introduction to Design Patterns o What is a Design Pattern o Why Study Design Patterns o History of Design Patterns o The Gang of Four • The Singleton Pattern o Introduction o Logger Example o Lazy Instantiation o Limitations Abstract Factory Pattern o Abstract Factory in real life o Example o Real life vs Java Object o Limitations -ParamiSoft Systems Pvt. Ltd.
  • 3. What is a Design Pattern? • A problem that someone has already solved. • A model or design to use as a guide • More formally: “A proven solution to a common problem in a specified context." Real World Examples • Blueprint for a house • Manufacturing -ParamiSoft Systems Pvt. Ltd.
  • 4. Why Study Design Patterns? • Provides software developers a toolkit for handling problems that have already been solved. • Provides a vocabulary that can be used amongst software developers. o The Pattern Name itself helps establish a vocabulary • Helps you think about how to solve a software problem. -ParamiSoft Systems Pvt. Ltd.
  • 5. History of Design Patterns • Christopher Alexander (Civil Engineer) in 1977 wrote o “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.” • Each pattern has the same elements o Pattern Name – helps develop a catalog of common problems o Problem – describes when to apply the pattern. Describes problem and its context. o Solution – Elements that make up the design, their relationships, responsibilities, and collaborations. o Consequences – Results and trade-offs of applying the pattern -ParamiSoft Systems Pvt. Ltd.
  • 6. The Gang of Four • Defines a Catalog of different design patterns. • Three different types o Creational – “creating objects in a manner suitable for the situation” o Structural – “ease the design by identifying a simple way to realize relationships between entities” o behavioural– “common communication patterns between objects” -ParamiSoft Systems Pvt. Ltd.
  • 7. The Gang of Four: Pattern Catalog Creational Abstract Factory Builder Factory Method Prototype Singleton Structural Adapter Bridge Composite Decorator Façade Flyweight Proxy Behavioral Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor Patterns in red we will discuss in this presentation -ParamiSoft Systems Pvt. Ltd.
  • 9. Singleton • Definition: “The Singleton Pattern ensures a class has only one instance, and provides a global point of access to it.” • Best Uses o Logging o Caches o Registry Settings o Access External Resources • Printer • Device Driver • Database -ParamiSoft Systems Pvt. Ltd.
  • 10. Example: Logger What is wrong with this code? public class Logger { public Logger() { } public void LogMessage() { //Open File "log.txt" //Write Message //Close File } } -ParamiSoft Systems Pvt. Ltd.
  • 11. Example: Logger • Since there is an external Shared Resource (“log.txt”), we want to closely control how we communicate with it. • We shouldn’t have to create the Logger class every time we want to access this Shared Resource. Is there any reason to? • We need ONE. -ParamiSoft Systems Pvt. Ltd.
  • 12. Logger – as a Singleton public class Logger { private Logger{} private static Logger uniqueInstance; public static Logger getInstance() { if (uniqueInstance == null) uniqueInstance = new Logger(); return uniqueInstance; } } Note the parameterless constructor -ParamiSoft Systems Pvt. Ltd.
  • 13. Lazy Instantiation • Objects are only created when it is needed • Helps control that we’ve created the Singleton just once. • If it is resource intensive to set up, we want to do it once. -ParamiSoft Systems Pvt. Ltd.
  • 14. Singleton Consequences • Controlled access to sole instance facilitates strict control over when and how the clients access it • The singleton patter is improvement over global variables. • It is easy to configure an instance of the application that extends the functionality of singleton at run-time • More flexible than class operations -ParamiSoft Systems Pvt. Ltd.
  • 15. Singleton Limitations • The main limitation of the singleton pattern is that is permits the creation of only one instance of the class, while most practical applications require multiple instances to be initialized. • Furthermore, in case of singleton, the system threads fight to access the single instance thereby degrading the performance of the applications. -ParamiSoft Systems Pvt. Ltd.
  • 17. Abstract Factory Pattern is similar to Sub Contracting in real world. Basically delegating the creation of Objects to expert Factories ----------------------------------- Orders in a restaurant are received by a Kitchen. Then are assigned to Special Chefs like Chinese, Indian, Continental. Abstract Factory Pattern is a Creational Pattern. Similar to Factory Pattern it is Object Creation without exposing “HOW” ? Abstract Factory Pattern in Real Life -ParamiSoft Systems Pvt. Ltd.
  • 18. Abstract Factory Pattern in Java -ParamiSoft Systems Pvt. Ltd.
  • 19. Factory Kitchen Real Life vs Java Object -ParamiSoft Systems Pvt. Ltd.
  • 20. 1 Orders a Dish from Menu 2 Receives the Order Creates the Dish 4 Delivers the Dish 3 Outsources to Chef How Factory Pattern works in Real Life ?
  • 21. KitchenFactory factory = new KitchenFactory(); Food dosa = factory.getFood("Dosa"); dosa.print(); Food noodles = factory.getFood("Noodles"); noodles.print(); public Food getFood(String name) { if (name.equals("Dosa")) { IndianFactory factory = new IndianFactory(); return factory.getFood(name); } else if (name.equals("Noodles")) { ChineseFactory factory = new ChineseFactory(); return factory.getFood(name); } Return null;} 1 4 Food Dosa Noodles 2 3 Create food from Respective Factory Class How Factory Pattern works in Java? -ParamiSoft Systems Pvt. Ltd.
  • 22. Abstract Factory Consequences • Isolate concrete classes. • Make exchanging product families easy. • Promote consistency among products -ParamiSoft Systems Pvt. Ltd.
  • 23. Abstract Factory Limitation • Supporting new kinds of products is difficult. -ParamiSoft Systems Pvt. Ltd.
  • 24. References Links o http://en.wikipedia.org/wiki/Design_pattern o http://sourcemaking.com/design_patterns Links o Design Patterns in Ruby – Russ Olsen o Head First Design Patterns – Elisabeth Freeman, Eric Freeman, Bert Bates and Kathy Sierra -ParamiSoft Systems Pvt. Ltd.