Difference IoC container and Factory pattern

原创 2012年03月30日 15:43:18

   1 I would suggest to keep the concepts plain and simple. Dependency Injection is more of a architectural pattern for loosely coupling software components. Factory pattern is just one way to separate the responsibility of creating objects of other classes to another entity. Factory pattern can be called as a tool to implement DI. Dependency injection can be implemented in many ways like DI using constructors, using mapping xml files etc.


    2 Inversion of Control (IoC) and Dependency Injection (DI) usually refer to the same thing. IoC is a more general concept (instead of doing X itself, a class relies on some other class to do it) DI is IoC as applied to dependent classes (instead of creating a class that I depend on, it will be passed to me). DI is the most common use of IoC, so usually when they are discussed the terms are used interchangeably.


The Factory Pattern's main concern is creating things - DI's main concern is how things are connected together.

In practice, these two concerns (creating and connecting) are usually related, so most DI/IoC containers do both. You could think of most implementations as very configurable factories - but because the implementations address both concerns - not because the Factory pattern and DI/IoC are the same.

Introduction to the Spring IoC container and beans

3 The IoC container(IOC容器)3.1 Introduction to the Spring IoC container and beans(Spring IOC容器与beans的...

抽象工厂的初次尝试 ((15c++ Homework) polymorphic and OOP design pattern Abstract Factory)

首先介绍我通过这题所理解的抽象工厂:所谓抽象工厂,就是把一些类看做工厂类,专门用来new产品类,而产品类所要实现的就是构造函数,和一些简单的方法。这种写法的好处在于,有效地提高了代码的封装性,符合面向...

小谈抽象工厂模式与工厂方法,Abstract Factory Pattern and Factory Method

问题:从我所阅读的材料中,我看到:工厂方法模式允许你定义一个方法,这个方法可以创建一个实实在在的商品,但是却隐藏了实现细节,这样客户(client)可以得到产品。我第一个问题是关于抽象工厂:是不是抽象...
  • gusgao
  • gusgao
  • 2016年08月10日 22:59
  • 268

MVC or MVP Pattern – Whats the difference?

Over the years I have mentored many developers on using design patterns and best practices. One ques...
  • jzp_cn
  • jzp_cn
  • 2011年05月29日 15:33
  • 729

Difference_between_PLMN_and_PSTN

  • 2008年11月06日 10:48
  • 41KB
  • 下载

Difference between ScrollView and ListView

初学Android的时候曾经遇到过在ScrollView中使用ListView的情况。在ScrollView中使用ListView会出现的情况就是你在使用的时候会出现滚动不协调的情况。 下面就是一般对...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Difference IoC container and Factory pattern
举报原因:
原因补充:

(最多只允许输入30个字)