SlideShare ist ein Scribd-Unternehmen logo
1 von 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.

Weitere ähnliche Inhalte

Was ist angesagt?

Builder pattern
Builder patternBuilder pattern
Builder pattern
Shakil Ahmed
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
11prasoon
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
Aman Jain
 

Was ist angesagt? (20)

Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton Pattern
 
Design Patterns
Design PatternsDesign Patterns
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
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Abstract Factory Design Pattern
Abstract Factory Design PatternAbstract Factory Design Pattern
Abstract Factory Design Pattern
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Prototype_pattern
Prototype_patternPrototype_pattern
Prototype_pattern
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Class diagrams
Class diagramsClass diagrams
Class diagrams
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Design Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract FactoryDesign Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract Factory
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Design pattern
Design patternDesign pattern
Design pattern
 

Ähnlich wie Design pattern (Abstract Factory & Singleton)

Automating Ensemble Monitoring and Reporting
Automating Ensemble Monitoring and ReportingAutomating Ensemble Monitoring and Reporting
Automating Ensemble Monitoring and Reporting
InterSystems Corporation
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
Clay Helberg
 

Ähnlich wie 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
 

Mehr von 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
 

KĂźrzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

KĂźrzlich hochgeladen (20)

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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

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.