zoukankan      html  css  js  c++  java
  • 23种设计模式之门面模式

    //这是基于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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="bs" class="com.dz147.Validator.BookServiceImpl"/> <bean id="bs2" class="com.dz147.Validator.BookServiceImpl2"/> </beans>
    package com.dz147.Validator;
    
    public interface BookService {
        public void getInfo();
    }
    
    //实现
    public class BookServiceImpl implements BookService {
        @Override
        public void getInfo() {
            System.out.println("这是第一个实现");
        }
    }

    使用

    public class TestSpring {
        public static void main(String[] args) {
            ClassPathXmlApplicationContext cc =
                    new ClassPathXmlApplicationContext("spring/testSpring.xml");
            Object bs = cc.getBean("bs2");
            ((BookService)bs).getInfo();
        }
    }

    以上是基于XML

    使用java注解

    //使用java注解把对象放入Ioc容器中

    @Configuration
    public class BookServiceJavaStyle {
    
        @Bean
        public BookService xxx(){
            return new BookServiceImpl2();
        }
    }
    public class BookServiceImpl2 implements BookService {
        @Override
        public void getInfo() {
            System.out.println("这是第二个实现");
        }
    }
    public class TestSpring {
        public static void main(String[] args) {
            /*ClassPathXmlApplicationContext cc =
                    new ClassPathXmlApplicationContext("spring/testSpring.xml");
            Object bs = cc.getBean("bs2");
            ((BookService)bs).getInfo();*/
            //java注解方式
            newJavaStyle();
        }
    
        public static void newJavaStyle() {
            AnnotationConfigApplicationContext acc =
                    new AnnotationConfigApplicationContext(BookServiceJavaStyle.class);
            acc.getBean(BookService.class).getInfo();
        }
    }
  • 相关阅读:
    docker node中uid与gid的授权问题
    windows下docker无法进行端口映射的问题
    IOS/Safari下document对象的scrollHeight值比Chrome更大
    Vue/Egg大型项目开发(二)数据库设计
    .babelrc和babel.config.js的相同配置不能合并
    es6 class中责任链模式与AOP结合
    JS设计模式(10)职责链模式(重要)
    Vue/Egg大型项目开发(一)搭建项目
    你不知道的JS(3)来聊聊this
    CentOS7为php7.2安装php-redis扩展(redis环境搭建二)
  • 原文地址:https://www.cnblogs.com/dzcici/p/10112910.html
Copyright © 2011-2022 走看看