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 6168003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:36:40+00:00 2026-05-23T22:36:40+00:00

would this still count as the factory pattern if I would use, instead of

  • 0

would this still count as the factory pattern if I would use, instead of a parameter, use single methods.

For example instead of this

public class MapperFactory { // will be made as an instance

    public Mapper<?> typeMapper(String type)
    {
                switch(type){
                case "option1": return new MapperType1();
                case "option2": return new MapperType2();
                case "option3": return new MapperType3();
                }
    }
}

create a class like this so you just need to choose ‘MapperFactory.option1();’ instead of using ‘MapperFactory.typeMapper(“option1”);

public class MapperFactory { // will be made as an instance

        public Mapper<?> option1(){return new MapperType1();}
        public Mapper<?> option2(){return new MapperType2();}
        public Mapper<?> option3(){return new MapperType3();}
}

Greets

  • 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-23T22:36:40+00:00Added an answer on May 23, 2026 at 10:36 pm

    I don’t know if there’s a hard-and-fast rule here, but in my opinion, your second example is not a factory pattern. I think a factory pattern needs to allow for some sort of dynamic behavior in the implementation. In other words, the method must require input (even if the factory method takes no formal parameters, it must obtain some input to affect the implementation, be it via fields of the enclosing class, or some static data obtained elsewhere) and it must allow for the possibility of returning different types based on that input. I think your second example is simply a series of methods that instantiate a precise class and returns it.

    So now I ask, why are you exploring a factory pattern in the first place? If, at compile time, you always want to instantiate the same class (i.e. MapperFactory.option1()) why don’t you just use the new operator in the first place? In your second example, your “factory” methods provide absolutely no advantage over the stock new operator.

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

Sidebar

Related Questions

Would this work on all platforms? i know windows does \r\n, and remember hearing
Under what circumstances would this or would this not be safe? I have a
Comment on Duplicate Reference: Why would this be marked duplicate when it was asked
This would be a question for anyone who has code in the App_Code folder
This would be my issue I have a drop down that's not displaying fully.
This would be very handy as typecasting gets boring fast.
I would have thought this would be an easy one to Google, but I've
I know this would be easy with position:fixed, but unfortanately I'm stuck with supporting
I realize this would violate convention, but I'm curious to know if you can
I would like this to be the ultimate discussion on how to check if

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.