Announcement Announcement Module
Collapse
No announcement yet.
Factory vs Ioc Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Factory vs Ioc

    What difference betwen Factory Pattern and IoC/DEpendecy Injections?

  • #2
    A Factory is an object that is responsible for Object creation.

    Dependency Injection is a technique to remove the responsibility of creating dependencies (objects) and place it outside the object.

    So a class that uses dependency injection doesn't know anything about how objects are created. It could be that the dependency eventually is created by a Factory.. but it also could be that is created with an ordinary constructor call.

    So they are not competing patterns.

    example:

    Code:
    PersonDao dao = personDaoFactory.create();
    PersonService service = new PersonService(dao);
    The dao is created with a Factory, and the service relies on DI to get a usable dao.

    Comment

    Working...
    X