Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:23:39+00:00 2026-06-10T21:23:39+00:00

I’m reading about the Factory Method pattern. I can understand when there is a

  • 0

I’m reading about the Factory Method pattern.

I can understand when there is a single factory class, i.e. StoreFactory#getStore(), that returns a Store implementation based on some runtime or other state.

But, from reading (e.g. this link), there seems to be a general pattern of people creating an abstract factory class, to which other factory classes extend:

 public abstract class AbstractFactory {
     public abstract Store getStore(int store);
 }

 public class StoreFactoryA extends AbstractFactory {
     public Store getStore(int Store) {
         if(Store == 1) { return new MyStoreImplA(); }
         if(Store == 2) { return new MyStoreImplB(); }
     }
 }

 public class StoreFactoryB extends AbstractFactory {
     public Store getStore(int Store) {
         if(Store == 1) { return new MyStoreImplC(); }
         if(Store == 2) { return new MyStoreImplD(); }
     }
 }

 public class Runner {
    public static void main(String[] args) {
        AbstractFactory storeFactory = new StoreFactoryA();
        Store myStore = storeFactory.getStore(1);
    }
 }

My example is contrived, but models that of the aforementioned link.

This implementation seems kind of chicken-egg to me. Use the Factory Method pattern to eliminate the need for the client code to specify a class type, yet now the client code needs to selectively choose the correct factory to use, i.e. StoreFactoryA, StoreFactoryB?

What is the reasoning behind using the abstract class here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:23:40+00:00Added an answer on June 10, 2026 at 9:23 pm

    The link you are reading unfortunately does not give a realistic example of the pattern. In fact, as per the original GoF Design Patterns, this pattern is called Abstract Factory (Factory method is a different pattern).

    Abstract Factory pattern is used when you have factories that can create a family of objects. e.g. You can have and AbstractGUIFactory which can have methods createButton(), createWindow(), createTitleBar etc. And then, you would have concrete factories like WindowsGUIFactory, MacGUIFactory, MotifGUIFactory etc, each of which will produce Button, Window, TitleBar objects in their own way.

    The factory will be set to one implementation at some point in the application (probably using configuration) and then that factory will be used wherever the objects need to be created.

    If you are learning Design Patterns, the best advice is to start with the classic GoF book.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.