• facade模式


    GuoZai.java

    package edu.facade2;
    
    public class GuoZai {
        public void mai() {
            System.out.println("买股票");
        }
    }

    GuPiao.java

    package edu.facade2;
    
    public class GuPiao {
        public void cao() {
            System.out.println("炒股票");
        }
    }

    QiHuo.java

    package edu.facade2;
    
    public class QiHuo {
        public void gou() {
            System.out.println("购期货");
        }
    }

    JinJi.java

    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();
        }
    }

    关系图

    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>
    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();
        }
    }
  • 相关阅读:
    DOS命令如何删除文件和文件夹
    屏蔽电信流氓弹出广告
    Wcf客户端配置里Endpoint的Name属性无效
    正则替换中的一个Bug
    【原】解决 iframe 在 iPad 上不能滚动的问题
    【原】JSON.parse() 和 JSON.stringify()
    【原】SQL 使用 PIVOT 和 UNPIVOT 行转列 列转行
    【原】How to fix: Handler “PageHandlerFactoryIntegrated” has a bad module “ManagedPipelineHandler” in its module list
    【原】DES Encrypt / Decrypt
    【原】JSON.parse() 和 JSON.stringify()
  • 原文地址:https://www.cnblogs.com/jianfengyun/p/3734356.html
Copyright © 2020-2023  润新知