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

  • Home
  • SEARCH
  • 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 7577289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:08:49+00:00 2026-05-30T17:08:49+00:00

I have below example of abstract method patter. public interface Product { public void

  • 0

I have below example of abstract method patter.

public interface Product {
    public void draw();     
    public void move();
}

public abstract class Creator {     
    public Product anOperation() {
        Product product = factoryMethod();
        return product;
    }

    public abstract Product factoryMethod();
}

public class ConcreateProduct1 implments Product {
    public void draw() {        
    }

    public void move():
    }
}

public class ConcreteCreator1 extends Creator {
    public Product factoryMethod() {
        return new ConcreateProduct1();
    }
}

public class Client {
    public static void main(String arg[]) {
        Creator creator = null;
        creator = new ConcreteCreator1();
        creator.anOperation().move();
    }
}

So far I have read that flexibility to add new product is the main advantages of factory method pattern.

Can anybody explain me how we achieve flexibility which we can not achieve in below example?

public class ConcreateProduct1 {
    public void draw() {        
    }

    public void move():
    }
}

public class Client {
    public static void main(String arg[]) {
        ConcreateProduct1 creator = new ConcreteCreator1();
        creator.move();
    }
}
  • 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-05-30T17:08:52+00:00Added an answer on May 30, 2026 at 5:08 pm

    In your example it’s mostly useless. I think the Factory pattern is never needed: you can always do the same thing in some other way, but sometimes it’s convenient to use for some reason. For example it can be used for limiting resources usage in combination with a private constructor – it’s a cache strategy.

    There is also another interesting usage when coupled with reflective code. Imagine you write the Factory class without knowing any concrete implementation of the interface. The most common example is the JDBC API. From client code you access a database via a URL like <driverId>:<params>. The Factory has a HashMap<String, Class> so it can instantiate the correct type based on <driverId> with this code

    Class driverClass = drivers.get(driverId);
    Constructor constructor = driverClass.getDeclaredConstructor();
    return constructor.newInstance(params);
    

    The Factory vendor won’t need to change the implementation to add new Drivers, because they are dinamically registered and instantiated (in jdbc this happens via Class.forName("com.example.Driver")). Note that this still seems like an unneeded complexity: why using a factory just to get an istance of a class you must know? In this case the clear advantage is flexibility: the driver name is a String which can be externalized (for example in a configuration file). This way the final user (not the developer) can switch between drivers without recompiling the application.

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

Sidebar

Related Questions

I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
How can I select the good method (I have in the example below show
I have following method in my class which extends JTable: protected void setTableCursor(Cursor cursor)
I have 1 abstract class that is calling a static method which up until
I have an abstract Catalog class as follows. It has a static method OpenCatalog()
In the example below I have a ListBox with dozens of font names in
Let's consider the below example. There, I have: target MAIN calls target t and
I have a basic PHP question, take the code below for example, let's say
I have an example function below that reads in a date as a string
Below I have a very simple example of what I'm trying to do. I

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.