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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:06:07+00:00 2026-05-28T19:06:07+00:00

We are working on an application to process various XML messages and load them

  • 0

We are working on an application to process various XML messages and load them into a datastore. One of the devs I am working with created a Singleton Factory utilizing reflection to create an instance of the appropriate message subclass. My question is around using a singleton for the factory…(Using the samething for building the SqlCommand object need to pass to DB). The factory definitely makes sense here the part I am fuzzy about is using Singleton in conjunction with the Factory.

I have read a lot of postings, stackoverlow responses, etc and it still isn’t clear to me why for this scenario we would use that pattern (Singleton with factory…I would assume just use a factory pattern?).

Just trying to better understand as what I have gathered you would want to use Singleton when you want to ensure one and only one interface?

  • 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-28T19:06:08+00:00Added an answer on May 28, 2026 at 7:06 pm

    Singletons do not ensure a single interface; they ensure a single instance of an object that is accessible globally to other objects. An example of where you might want to use a singleton is when you need a counter that is accessible from anywhere in the application. In other words the state of that single object is maintained throughout the applications lifetime.

    Factories on the other hand are used to create object where you do not necessarily know the exact type of class that is returned. For example, you may have a factory that returns an automobile object but the exact class that is returned might be a Volkswagen or it might be a Ferrari.

    Factories are used a lot for dependency injection (DI). So in the example you give you can use a factory to return an object that interfaces with a DB, but the actual class may interface with a DB using SQL statements or maybe it is another class that uses an object-relational mapping (ORM) framework. This decouples the actual database interface/implementation from the rest of the application and allows more flexibility in changes to DB access going forward. The factory could even return a mockup of the DB access that can be used for unit testing. DI can be used to change which method is used at run-time. I would definitively recommend using Factories for these reasons.

    Factories can also return singletons. So the question to ask in determining if you need a singleton is, do I need to maintain state across the application for all of the objects that will access this. An example of wanting to maintain state is that you want to keep the connection open to the database for any object that accesses this DB object for the life of the application. Not suggesting you do this but it just an example of why you may want to maintain the state information of that object for the life of the application.

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

Sidebar

Related Questions

I am working on development of an application to process (and merge) several large
I've been working on a silverlight application which generates various graphs. It requires a
I am working on a database application that runs on various independent servers. Each
i had a working application until i changed the package name in the AndroidManifest.xml.
I'm working on desktop application (Extract Transform Load type of app) that requires uploading
I am working on an application for Windows Phone platform. Run into a question.
I'm working on an application that's supposed to read and process flat files. These
I am working on splitting out an existing, working application that I currently have
I've try to implement integration tests for a working application (spring, hibernate, soap, cxf).
i am working in application of twitter in flex 3 and action script 3

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.