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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:07:50+00:00 2026-05-27T20:07:50+00:00

The standard factory Method design pattern talks of 4 classes. Creator,Product n their concrete

  • 0

The standard factory Method design pattern talks of 4 classes.
Creator,Product n their concrete implementations.

So for each product we need to instantiate corresponding factory which has methods to create the product.

But I have also seen scenarios where people declare constructor as private and have a static method that creates an object of the same class. Something similar to what we do with singletons.

For example getByname is one of the static methods of InetAddress that returns one of its subclass depending upon whats the parameter.
and people call it factory method.

Is this also an example of factory method pattern ?
does it contain if-else-if inside the method to decode the parameter or switch statement ?
But isnt use of switch n conditional statements considered a bad OO design practice ?

  • 1 1 Answer
  • 1 View
  • 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-27T20:07:50+00:00Added an answer on May 27, 2026 at 8:07 pm

    Yes, this is an example of the factory method pattern.

    Ans yes, it parses its argument and decides which kind of address (which subclass) to instantiate (this is easily findable by looking at the source code of the method, which comes with the JDK).

    At some point, you have to use conditional statements. It’s not necessarily bad practice. In this case, the factory method is precisely there to encapsulate the address parsing and return the appropriate subclass, rather than having to do it in the caller. What would be bad OO practice would be to be forced to write:

    int addressType = InetAddress.getAddressType(address);
    InetAddress ia = null;
    switch (addressType) {
        case V4 : 
            ia = new Inet4Address();
            break;
        case V6 : 
            ia = new Inet6Address();
            break;
        default :
            throw new RuntimeException("bad address");
    }
    

    Instead, this logic is encapsulated into the factory method.

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

Sidebar

Related Questions

Why is it a standard deign to implement Factory classes as singleton? What is
The standard GET query as a link for each user is easy but ugly
Can standard pointers in .Net do this? Or does one need to resort to
So standard Agile philosophy would recommend making your domain classes simple POCOs which are
Here is my configuration: this.factory = Fluently.Configure(). Database(SQLiteConfiguration.Standard.UsingFile(foo.db). ShowSql()). Mappings(m => m.FluentMappings.AddFromAssemblyOf<Bar>()). ExposeConfiguration(BuildSchema). BuildSessionFactory();
I have the convenient object factory template that creates objects by their type id
Standard Entry Sequence : _function: push ebp ;store the old base pointer mov ebp,
standard power operation ( ** ) in Python does not work for negative power!
In standard ASP.net applications ASP.net offered some protection from XSS attacks with validateRequest throwing
The standard model has been that OpenGL is for professional apps (CAD) and Direct3D

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.