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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:06:47+00:00 2026-05-12T16:06:47+00:00

Our application makes heavy use of factories to spit out objects, but I often

  • 0

Our application makes heavy use of factories to spit out objects, but I often wonder if they are always really necessary, and it wouldn’t simply be better to create an instance of a “known object” as a bean. The argument is that developers are often customizing the implementation of these returned objects (which are returned with their interface type), and since we don’t technically “know” exactly what we’re getting, it is better to use the factory. I’m at the point where I need to create a factory, which requires the interface, the class implementation, and then the factory. My object isn’t going to change though — it really is a concrete object with a specific purpose… shouldn’t I just instantiate a bean that gets and sets the state? I’m trying to avoid premature generalization.

  • 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-12T16:06:47+00:00Added an answer on May 12, 2026 at 4:06 pm

    The whole purpose of a factory or dependency injection solution is reduce coupling between the client and the runtime type of the object. It’s true that the client has to know the interface and the source of the data, but now the source is free to return any type that implements the interface. It also allows you to encapsulate the knowledge of the runtime type in one place – only the factory or dependency injection solution needs to know.

    This is helpful when generating runtime proxies to implement declarative transactions. From the client’s point of view, they’re dealing with the interface. The factory can generate the proxy that manages transactions for the client.

    Once you type “new”, the client is tied to using the compile type at runtime. Changing it means changing the client. If you have lots of places where you call “new” in your code that can be a maintenance problem.

    When do I call “new”? I think it’s appropriate inside a method to instantiate local objects that will be GC’d when they go out of scope. The method creates them, uses them, and then they’re done. I would not use a factory or DI solution there.

    Maybe you should close your factories and consider a dependency injection solution like Spring, Guice, or PicoContainer.

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

Sidebar

Related Questions

Our project has about 20 developers, but our application makes relatively light use of
I'm auditing our existing web application, which makes heavy use of HTML frames .
Our PHP application makes use of json_encode($myObject) a lot, in conjunction with the mustache
We're getting ready to deploy a commercial application. Our software makes use of several
The web client of our application makes use of xforms. A message box pops
We are considering switching to MySQL for our application. Our code makes extensive use
The application i am currently working on makes heavy use of the repository pattern
Our application used to make use of a common base form that all forms
Sometimes in order to make our application more responsive and fast, we use client
OK, so we're writing our MFC application to make use of the built-in localization

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.