@yanong_banikanhon, as to your question what a Factory pattern is and what IOC is, well... there are plenty of resources available in the web. A simple Google search will do the trick. But here's a simple example...
Consider the difference when using the Factory pattern:
PHP Code:
public class MyUserClass {
public void detonateBomb() {
MyWarInterface mwi = MyFactory.getCurrentWarClass();
mwi.detonateBomb();
}
}
And this one with (IOC) Dependency Injection in Spring:
PHP Code:
public class MyUserClass {
private MyWarInterface mwi;
public void detonateBomb() {
mwi.detonateBomb();
}
public void setMwi(MyWarInterface mwi) {
this.mwi = mwi;
}
}
(Spring) Dependency Injection xml config file:
PHP Code:
<bean id="myTerrorist" class="com.istorya.MyTerrorist"/>
<bean id="myPatriot" class="com.istorya.MyPatriot"/>
You can use either implementing class with:
PHP Code:
<bean id="myUserClass" class="com.istorya.MyUserClass">
<property name="mwi" ref="myTerrorist"/>
</bean>
or
PHP Code:
<bean id="myUserClass" class="com.istorya.MyUserClass">
<property name="mwi" ref="myPatriot"/>
</bean>
Your MyUserClass has no idea who the implementing class is for MyWarInterface which means that switching implementing classes won't affect the MyUserClass.
If you want to add a third implementing class say 'MySpy' class that implements MyWarInteface, then just add another bean instance. You can then switch to this new implementing class that blows both Obama and Bin Laden to the moon! 
PHP Code:
<bean id="mySpy" class="com.istorya.MySpy"/>
<bean id="myUserClass" class="com.istorya.MyUserClass">
<property name="mwi" ref="mySpy"/>
</bean>