Explain Factory and abstract Factory Design Pattern

Posted on 2011-10-18
Last Modified: 2013-11-24
Explain Factory and abstract Factory Design Pattern
Question by:stmani2005
    LVL 4

    Expert Comment


    Check the following url:


    LVL 8

    Author Comment

    could you please explain with own word and example for factory and abstract factory
    LVL 4

    Accepted Solution

    The Factory patterns can be used in following cases:

    1. When a class does not know which class of objects it must create.
    2. A class specifies its sub-classes to specify which objects to create.
    3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.


    public Person getPerson(String name, String gender) {
        if (gender.equals("M"))
            return new Male(name);
        else if(gender.equals("F"))
           return new Female(name);
           return null;

    Open in new window

    LVL 4

    Expert Comment

    Abstract Factory patterns:

    One of the main advantages of Abstract Factory Pattern is that it isolates the concrete classes that are generated. The names of actual implementing classes are not needed to be known at the client side. Because of the isolation, you can change the implementation from one factory to another.

    example could be the same as a normal factory pattern but with a abstract-factory the super class of the objects is abstract

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now