码迷,mamicode.com
首页 > 其他好文 > 详细

facade模式

时间:2014-05-18 00:34:50      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   java   

GuoZai.java

bubuko.com,布布扣
package edu.facade2;

public class GuoZai {
    public void mai() {
        System.out.println("买股票");
    }
}
bubuko.com,布布扣

GuPiao.java

bubuko.com,布布扣
package edu.facade2;

public class GuPiao {
    public void cao() {
        System.out.println("炒股票");
    }
}
bubuko.com,布布扣

QiHuo.java

bubuko.com,布布扣
package edu.facade2;

public class QiHuo {
    public void gou() {
        System.out.println("购期货");
    }
}
bubuko.com,布布扣

JinJi.java

bubuko.com,布布扣
package edu.facade2;

public class JiJin {
    private GuoZai guoZai;
    private GuPiao guPiao;
    private QiHuo qiHuo;

    public GuoZai getGuoZai() {
        return guoZai;
    }

    public void setGuoZai(GuoZai guoZai) {
        this.guoZai = guoZai;
    }

    public GuPiao getGuPiao() {
        return guPiao;
    }

    public void setGuPiao(GuPiao guPiao) {
        this.guPiao = guPiao;
    }

    public QiHuo getQiHuo() {
        return qiHuo;
    }

    public void setQiHuo(QiHuo qiHuo) {
        this.qiHuo = qiHuo;
    }

    public void Mai() {
        guoZai.mai();
        qiHuo.gou();
        guPiao.cao();
    }
}
bubuko.com,布布扣

关系图

bubuko.com,布布扣

bubuko.com,布布扣
applicationContext2.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
    <bean id="guoZai" class="edu.facade2.GuoZai" />
    <bean id="guPiao" class="edu.facade2.GuPiao" />
    <bean id="qiHuo" class="edu.facade2.QiHuo" />
    <bean id="jiJin" class="edu.facade2.JiJin">
        <property name="guoZai" ref="guoZai"/>
        <property name="guPiao" ref="guPiao"/>
        <property name="qiHuo" ref="qiHuo"/>
    </bean>
</beans>
bubuko.com,布布扣
bubuko.com,布布扣
ClassTest2
package cn.itcast.dao.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import edu.facade2.JiJin;

public class ClassTest2 {
    @Test
    public void test() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext(
                "applicationContext2.xml");
        JiJin jiJin = (JiJin) ctx.getBean("jiJin");
        jiJin.Mai();
    }
}
bubuko.com,布布扣

 

facade模式,布布扣,bubuko.com

facade模式

标签:style   blog   class   code   c   java   

原文地址:http://www.cnblogs.com/jianfengyun/p/3734356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!