<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSpring%2FIoC_Config</id>
		<title>Java/Spring/IoC Config - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSpring%2FIoC_Config"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Spring/IoC_Config&amp;action=history"/>
		<updated>2026-04-21T10:41:57Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Spring/IoC_Config&amp;diff=6511&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Spring/IoC_Config&amp;diff=6511&amp;oldid=prev"/>
				<updated>2010-06-01T06:15:57Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:15, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Spring/IoC_Config&amp;diff=6510&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Spring/IoC_Config&amp;diff=6510&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:44Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== IoC in properties file ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Pro Spring&lt;br /&gt;
By Rob Harrop&lt;br /&gt;
Jan Machacek&lt;br /&gt;
ISBN: 1-59059-461-4&lt;br /&gt;
Publisher: Apress&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
//File: beans.properties&lt;br /&gt;
# The View&lt;br /&gt;
view.class=StandardOutView&lt;br /&gt;
view.model(ref)=model&lt;br /&gt;
# The Model&lt;br /&gt;
model.class=HelloWorldModel&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public interface View {&lt;br /&gt;
    public void render();&lt;br /&gt;
    &lt;br /&gt;
    public void setModel(Model m);&lt;br /&gt;
    public Model getModel();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public interface Model {&lt;br /&gt;
  public String getMessage();&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public class StandardOutView implements View {&lt;br /&gt;
    private Model model = null;&lt;br /&gt;
    public void render() {&lt;br /&gt;
        if (model == null) {&lt;br /&gt;
            throw new RuntimeException(&lt;br /&gt;
                    &amp;quot;You must set the property model of class:&amp;quot;&lt;br /&gt;
                            + StandardOutView.class.getName());&lt;br /&gt;
        }&lt;br /&gt;
        System.out.println(model.getMessage());&lt;br /&gt;
    }&lt;br /&gt;
    public void setModel(Model m) {&lt;br /&gt;
        this.model = m;&lt;br /&gt;
    }&lt;br /&gt;
    public Model getModel() {&lt;br /&gt;
        return this.model;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldModel implements Model {&lt;br /&gt;
    public String getMessage() {&lt;br /&gt;
        return &amp;quot;Hello World!&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
import org.springframework.beans.factory.BeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;&lt;br /&gt;
public class HelloWorldSpring {&lt;br /&gt;
    public static void main(String[] args) throws Exception {&lt;br /&gt;
        // get the bean factory&lt;br /&gt;
        BeanFactory factory = getBeanFactory();&lt;br /&gt;
        View v = (View) factory.getBean(&amp;quot;view&amp;quot;);&lt;br /&gt;
        Model mp = (Model) factory.getBean(&amp;quot;model&amp;quot;);&lt;br /&gt;
        v.setModel(mp);&lt;br /&gt;
        v.render();&lt;br /&gt;
    }&lt;br /&gt;
    private static BeanFactory getBeanFactory() throws Exception {&lt;br /&gt;
        // get the bean factory&lt;br /&gt;
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();&lt;br /&gt;
        // create a definition reader&lt;br /&gt;
        PropertiesBeanDefinitionReader rdr = new PropertiesBeanDefinitionReader(&lt;br /&gt;
                factory);&lt;br /&gt;
        // load the configuration options&lt;br /&gt;
        Properties props = new Properties();&lt;br /&gt;
        props.load(HelloWorldSpring.class.getResource(&amp;quot;beans.properties&amp;quot;).openStream());&lt;br /&gt;
        rdr.registerBeanDefinitions(props);&lt;br /&gt;
        return factory;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== IoC XML Config ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Pro Spring&lt;br /&gt;
By Rob Harrop&lt;br /&gt;
Jan Machacek&lt;br /&gt;
ISBN: 1-59059-461-4&lt;br /&gt;
Publisher: Apress&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
//File: beans.properties&lt;br /&gt;
# The View&lt;br /&gt;
view.class=StandardOutView&lt;br /&gt;
view.model(ref)=model&lt;br /&gt;
# The Model&lt;br /&gt;
model.class=HelloWorldModel&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public interface Model {&lt;br /&gt;
  public String getMessage();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public interface View {&lt;br /&gt;
    public void render();&lt;br /&gt;
    &lt;br /&gt;
    public void setModel(Model m);&lt;br /&gt;
    public Model getModel();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
public class StandardOutView implements View {&lt;br /&gt;
    private Model model = null;&lt;br /&gt;
    public void render() {&lt;br /&gt;
        if (model == null) {&lt;br /&gt;
            throw new RuntimeException(&lt;br /&gt;
                    &amp;quot;You must set the property model of class:&amp;quot;&lt;br /&gt;
                            + StandardOutView.class.getName());&lt;br /&gt;
        }&lt;br /&gt;
        System.out.println(model.getMessage());&lt;br /&gt;
    }&lt;br /&gt;
    public void setModel(Model m) {&lt;br /&gt;
        this.model = m;&lt;br /&gt;
    }&lt;br /&gt;
    public Model getModel() {&lt;br /&gt;
        return this.model;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldModel implements Model {&lt;br /&gt;
    public String getMessage() {&lt;br /&gt;
        return &amp;quot;Hello World!&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
import org.springframework.beans.factory.BeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;&lt;br /&gt;
public class HelloWorldSpringWithDI {&lt;br /&gt;
    public static void main(String[] args) throws Exception {&lt;br /&gt;
        // get the bean factory&lt;br /&gt;
        BeanFactory factory = getBeanFactory();&lt;br /&gt;
        View mr = (View) factory.getBean(&amp;quot;view&amp;quot;);&lt;br /&gt;
        mr.render();&lt;br /&gt;
    }&lt;br /&gt;
    private static BeanFactory getBeanFactory() throws Exception {&lt;br /&gt;
        // get the bean factory&lt;br /&gt;
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();&lt;br /&gt;
        // create a definition reader&lt;br /&gt;
        PropertiesBeanDefinitionReader rdr = new PropertiesBeanDefinitionReader(&lt;br /&gt;
                factory);&lt;br /&gt;
        // load the configuration options&lt;br /&gt;
        Properties props = new Properties();&lt;br /&gt;
        props.load(HelloWorldSpringWithDI.class.getResource(&amp;quot;beans.properties&amp;quot;).openStream());&lt;br /&gt;
        rdr.registerBeanDefinitions(props);&lt;br /&gt;
        return factory;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Load Bean Definition From XML File ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Pro Spring&lt;br /&gt;
By Rob Harrop&lt;br /&gt;
Jan Machacek&lt;br /&gt;
ISBN: 1-59059-461-4&lt;br /&gt;
Publisher: Apress&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
//File: beans.xml&lt;br /&gt;
&amp;lt;!DOCTYPE beans PUBLIC &amp;quot;-//SPRING//DTD BEAN//EN&amp;quot; &amp;quot;http://www.springframework.org/dtd/spring-beans.dtd&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;beans&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
    &amp;lt;!-- oracle bean used for a few examples --&amp;gt;&lt;br /&gt;
    &amp;lt;bean id=&amp;quot;beanId&amp;quot; name=&amp;quot;beanName&amp;quot; class=&amp;quot;Bean&amp;quot;/&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&amp;lt;/beans&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public class Bean{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
public class XmlConfigWithBeanFactory {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource(&lt;br /&gt;
                &amp;quot;build/beans.xml&amp;quot;));&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lookup Demo ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Pro Spring&lt;br /&gt;
By Rob Harrop&lt;br /&gt;
Jan Machacek&lt;br /&gt;
ISBN: 1-59059-461-4&lt;br /&gt;
Publisher: Apress&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
//File: lookup.xml&lt;br /&gt;
&amp;lt;!DOCTYPE beans PUBLIC &amp;quot;-//SPRING//DTD BEAN//EN&amp;quot; &amp;quot;http://www.springframework.org/dtd/spring-beans.dtd&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;beans&amp;gt;&lt;br /&gt;
    &amp;lt;bean id=&amp;quot;helper&amp;quot; class=&amp;quot;MyHelper&amp;quot; singleton=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;bean id=&amp;quot;abstractLookupBean&amp;quot; class=&amp;quot;AbstractLookupDemoBean&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;lookup-method name=&amp;quot;getMyHelper&amp;quot; bean=&amp;quot;helper&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/bean&amp;gt;&lt;br /&gt;
    &amp;lt;bean id=&amp;quot;standardLookupBean&amp;quot; class=&amp;quot;StandardLookupDemoBean&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;property name=&amp;quot;myHelper&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;ref local=&amp;quot;helper&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/property&amp;gt;&lt;br /&gt;
    &amp;lt;/bean&amp;gt;&lt;br /&gt;
&amp;lt;/beans&amp;gt;&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public interface DemoBean {&lt;br /&gt;
    public MyHelper getMyHelper();&lt;br /&gt;
    public void someOperation();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public class MyHelper {&lt;br /&gt;
    public void doSomethingHelpful() {&lt;br /&gt;
        // do something!&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public class StandardLookupDemoBean implements DemoBean {&lt;br /&gt;
    private MyHelper helper;&lt;br /&gt;
    &lt;br /&gt;
    public void setMyHelper(MyHelper helper) {&lt;br /&gt;
        this.helper = helper;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public MyHelper getMyHelper() {&lt;br /&gt;
        return this.helper;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void someOperation() {&lt;br /&gt;
        helper.doSomethingHelpful();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public abstract class AbstractLookupDemoBean implements DemoBean {&lt;br /&gt;
    &lt;br /&gt;
    public abstract MyHelper getMyHelper();&lt;br /&gt;
    &lt;br /&gt;
    public void someOperation() {&lt;br /&gt;
        getMyHelper().doSomethingHelpful();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import org.springframework.beans.factory.BeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
import org.springframework.util.StopWatch;&lt;br /&gt;
public class LookupDemo {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        BeanFactory factory = new XmlBeanFactory(new FileSystemResource(&lt;br /&gt;
                &amp;quot;build/lookup.xml&amp;quot;));&lt;br /&gt;
        DemoBean abstractBean = (DemoBean) factory.getBean(&amp;quot;abstractLookupBean&amp;quot;);&lt;br /&gt;
        DemoBean standardBean = (DemoBean) factory.getBean(&amp;quot;standardLookupBean&amp;quot;);&lt;br /&gt;
        displayInfo(standardBean);&lt;br /&gt;
        displayInfo(abstractBean);&lt;br /&gt;
    }&lt;br /&gt;
    public static void displayInfo(DemoBean bean) {&lt;br /&gt;
        MyHelper helper1 = bean.getMyHelper();&lt;br /&gt;
        MyHelper helper2 = bean.getMyHelper();&lt;br /&gt;
        System.out.println(&amp;quot;Helper Instances the Same?: &amp;quot;&lt;br /&gt;
                + (helper1 == helper2));&lt;br /&gt;
        StopWatch stopWatch = new StopWatch();&lt;br /&gt;
        stopWatch.start(&amp;quot;lookupDemo&amp;quot;);&lt;br /&gt;
        for (int x = 0; x &amp;lt; 100000; x++) {&lt;br /&gt;
            MyHelper helper = bean.getMyHelper();&lt;br /&gt;
            helper.doSomethingHelpful();&lt;br /&gt;
        }&lt;br /&gt;
        stopWatch.stop();&lt;br /&gt;
        System.out.println(&amp;quot;100000 gets took &amp;quot; + stopWatch.getTotalTimeMillis()&lt;br /&gt;
                + &amp;quot; ms&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Simplest Usage of property config file In Spring ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
Pro Spring&lt;br /&gt;
By Rob Harrop&lt;br /&gt;
Jan Machacek&lt;br /&gt;
ISBN: 1-59059-461-4&lt;br /&gt;
Publisher: Apress&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
//File: msf.properties&lt;br /&gt;
renderer.class=StandardOutView&lt;br /&gt;
provider.class=HelloWorldModel&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public interface Model {&lt;br /&gt;
  public String getMessage();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
public interface View {&lt;br /&gt;
    public void render();&lt;br /&gt;
    &lt;br /&gt;
    public void setModel(Model m);&lt;br /&gt;
    public Model getModel();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
public class StandardOutView implements View {&lt;br /&gt;
    private Model model = null;&lt;br /&gt;
    public void render() {&lt;br /&gt;
        if (model == null) {&lt;br /&gt;
            throw new RuntimeException(&lt;br /&gt;
                    &amp;quot;You must set the property model of class:&amp;quot;&lt;br /&gt;
                            + StandardOutView.class.getName());&lt;br /&gt;
        }&lt;br /&gt;
        System.out.println(model.getMessage());&lt;br /&gt;
    }&lt;br /&gt;
    public void setModel(Model m) {&lt;br /&gt;
        this.model = m;&lt;br /&gt;
    }&lt;br /&gt;
    public Model getModel() {&lt;br /&gt;
        return this.model;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
public class HelloWorldModel implements Model {&lt;br /&gt;
    public String getMessage() {&lt;br /&gt;
        return &amp;quot;Hello World!&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
public class MessageSupportFactory {&lt;br /&gt;
    private static MessageSupportFactory instance = null;&lt;br /&gt;
    private Properties props = null;&lt;br /&gt;
    private View renderer = null;&lt;br /&gt;
    private Model provider = null;&lt;br /&gt;
    private MessageSupportFactory() {&lt;br /&gt;
        props = new Properties();&lt;br /&gt;
        try {&lt;br /&gt;
            props.load( MessageSupportFactory.class.getResource(&amp;quot;msf.properties&amp;quot;).openStream());&lt;br /&gt;
            // get the implementation classes&lt;br /&gt;
            String rendererClass = props.getProperty(&amp;quot;renderer.class&amp;quot;);&lt;br /&gt;
            String providerClass = props.getProperty(&amp;quot;provider.class&amp;quot;);&lt;br /&gt;
            renderer = (View) Class.forName(rendererClass).newInstance();&lt;br /&gt;
            provider = (Model) Class.forName(providerClass).newInstance();&lt;br /&gt;
        } catch (Exception ex) {&lt;br /&gt;
            ex.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    static {&lt;br /&gt;
        instance = new MessageSupportFactory();&lt;br /&gt;
    }&lt;br /&gt;
    public static MessageSupportFactory getInstance() {&lt;br /&gt;
        return instance;&lt;br /&gt;
    }&lt;br /&gt;
    public View getView() {&lt;br /&gt;
        return renderer;&lt;br /&gt;
    }&lt;br /&gt;
    public Model getModel() {&lt;br /&gt;
        return provider;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
public class HelloWorldDecoupledWithFactory {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        View mr = MessageSupportFactory.getInstance().getView();&lt;br /&gt;
        Model mp = MessageSupportFactory.getInstance().getModel();&lt;br /&gt;
        mr.setModel(mp);&lt;br /&gt;
        mr.render();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>