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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:17:02+00:00 2026-05-26T11:17:02+00:00

This is about the Factory Pattern. I am a little confused. I saw implementations

  • 0

This is about the Factory Pattern. I am a little confused.

I saw implementations where the createInstance() method is static and some implementations that are non-static.

Some say it’s depending on “style” or “taste” and some say it does not.
Wikipedia says that it should be non-static, and http://www.dofactory.com/Patterns/PatternFactory.aspx also says that it should be non-static, according to the Gang of Four.

My question is: does it depend on style & taste or does it violate the Factory Pattern if it’s implemented the static way? What’s right?

  • 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-26T11:17:03+00:00Added an answer on May 26, 2026 at 11:17 am

    Static method doesn’t violate the pattern but it goes against many other object oriented practices (inversion of control + dependency injection as one example) so using instances is better.

    Edit:

    I just got some badge for this answer but when I read it I could not believe my eyes. It is wrong when we strictly speak about GoF Factory method pattern and it deserves some correcting.

    You can have static CreateInstance method for creating instance of a type – there is nothing wrong about that – people often call it factory method but that is not what is called Factory Method pattern. Once you start putting logic into this method to create instances of different types depending on some condition you may be actually in need of Factory Method pattern described by GoF.

    The point of GoF Factory method pattern is to replace conditional logic inside CreateInstance with inheritance and polymorphism and thus it cannot be static. Factory method is an instance method – moreover it is virtual. Your base type has usually abstract CreateInstance and conditional logic is replaced by inheritance tree where each subtype overrides CreateInstance and creates just specific product for that subtype.

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

Sidebar

Related Questions

No, this is not a question about generics. I have a Factory pattern with
I've heard recently about the Abstract Factory Pattern and have currently some doubts on
This is another design pattern in some legacy code that I couldn't find much
This question about Timers for windows services got me thinking: Say I have (and
This is about a web app that serves images. Since the same request will
I was wondering if this is an 'unwholesome' use of a factory pattern, or
There are already quite some posts about the Singleton-Pattern around, but I would like
I have seen an implementation of Factory using static methods. Something like this: public
I have been reading about Factory pattern a lot lately. I am trying to
I've been reading up on the Factory pattern, and have come across articles that

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.