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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:39:13+00:00 2026-05-25T00:39:13+00:00

As per my understanding both Factory class and Spring DI follows the Dependency injection.

  • 0

As per my understanding both Factory class and Spring DI follows the Dependency injection. I mean in both the cases external entity is used to push the dependency. Right?
My question is which one i should go for between factory classes and Spring DI when my intention is just to get the objects . Assume i don’t want any other features like aop, dao support etc. Only purpose is to get the objects either from Factory class or Spring DI. Which one is preferable.

on some site read this statement

DI loosely coupled and less intrusive in comparison to Factory classes

But could not get how spring DI loosely coupled and less intrusive than factory classes?
in both the cases we have to insert some kind of get object code in our core program .

  • 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-25T00:39:14+00:00Added an answer on May 25, 2026 at 12:39 am

    Spring DI promotes loosely coupled code because the Spring container injects your dependencies based on configuration. If you are injecting interface implementations, you don’t have to change code to change which specific implementation gets injected, unless you consider your configuration code, which many do.

    If you use a Factory to create configured objects that are used by the rest of your code, you are writing code to create the objects, configure them, etc. If you want to change what the factory returns, you have to change actual code, which some would argue is a more intrusive change.

    Typically Spring is used to configure how the various layers of your application are wired together. X service takes such and such DAO implementations, for example. That’s application level organization. Lets say you have a scenario where want to create a button for every row in a list — in that case you could use a factory to create the buttons. This scenario is based on a runtime situation where the GUI has different elements that you couldn’t configure up front (because its based on the data), so DI makes less sense here.

    EDIT – based on your comment questions, I think the primary point here is that you have to consider is that Spring is also an Inversion of Control container. That means you don’t program in which components in your application go where. Without IoC, you might do something like

    MyServiceImpl extends MyService {
        Dao1 = new Dao1Impl(); // you programmatically configure which components go in here
        Dao2 = new Dao2Impl();
        ....
    }
    

    instead you do something like

    MyServiceImpl extends MyService {
        public Dao1;  // you haven't specified which components, only interfaces
        public Dao2;
        ....
    }
    

    In the second code sample, Spring (or whatever you use) will inject the appropriate DAO instances for you. You have moved control of which components to use to a higher level. So IoC and DI go hand and hand, IoC promotes loose coupling because in your component definitions (i.e. interfaces) you only specify behavior.

    In other words, IoC and DI are not necessary for loose coupling; you can have loose coupling with a Factory too

    MyServiceImpl extends MyService {
        public dao1 
        public dao2;
    
        MyServiceImpl(){
           dao1 = DaoFactory.getDao1();
           ...
        }
        ....
    }
    

    here your service still only depends on DAO definitions and you use the factory to get implementations. The caveat is that your service is now coupled to the factory. You can make it more loose by passing a Factory into your constructor if you want….

    Also, dont forget that Spring provides other useful functionalities, like its transaction management. That’s incredibly helpful, even though you said for your app you don’t need it.

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

Sidebar

Related Questions

as per my understanding about mvvm is. there is a model (entity class that
As per my understanding stateless session beans are used to code the business logic.
As per my understanding there will be one jvm instance and one class loader
As per my understanding a lock is not released until the runtime completes the
As per my understanding, JDBC Connection Pooling (at a basic level) works this way:
As per my understanding regarding N-Tier and SOA architecture. N-Tier N-Tier means dividing application
In below program i am getting output as false .But as per my understanding
As per my understanding scheme procedures like map,apply,append etc are written in scheme itself.
Equal Objects must have equal hashcodes. As per my understanding this statement is valid
As per my understanding, when a process enters a critical section, no other process

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.