接口


package FactoryExample; public interface Human {
void eat();
void walk();
void show();
}

实现

实现一


package FactoryExample; public class Man implements Human {
@Override
public void eat() {
System.out.println("男人吃饭,吃完饭打炮!");
} @Override
public void walk() {
System.out.println("男人走路,走完路打不了炮!");
} @Override
public void show() {
if (this.equals(null)) {
System.out.println("空对象");
} else {
this.eat();
this.walk();
}
}
}

实现二


package FactoryExample; public class Women implements Human {
@Override
public void eat() {
System.out.println("女人吃饭!吃完饭被干!");
} @Override
public void walk() {
System.out.println("女人走路,和男人一样!");
} @Override
public void show() {
if (this.equals(null)) {
System.out.println("空对象");
} else {
this.eat();
this.walk();
}
}
}

srping-config.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean>
<code>package FactoryExample; import org.apache.catalina.core.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext; public class SrpingTest {
public static void main(String[] args) {
FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext("src/spring-config.xml"); Human human = null; //返回 Object 类型 , 所以要加上 类型转换
human = (Human) ctx.getBean("man"); human.show(); human = (Human) ctx.getBean("women"); human.show(); }
}

就是这样,我的可以使用,我不知道为什么可以使用,但是就是可以使用!

来源:https://blog.csdn.net/lpZhouYi/article/details/85228122

最新文章

  1. [APUE]文件和目录(下)
  2. django关闭debug后,静态文件的处理
  3. 使用Merge Into 语句实现 Insert/Update
  4. oracle-5-的升级步骤
  5. Java异常--读书笔记
  6. [vijos P1014] 旅行商简化版
  7. Eclipse Gtk+
  8. leetcode: sortlist之四种方法
  9. sock
  10. SpringBoot2.0之四 简单整合MyBatis
  11. java0426 wen IO2
  12. EBS採购模块中的高速接收和高速接收事务
  13. python -- Pythonic
  14. Android:更好的自定义字体方案
  15. CentOS 安装 MongoDB
  16. JavaEE开发的颠覆者 Spring Boot实战--笔记
  17. openstack 的horizon的结构
  18. Python开发基础-Day17面向对象编程介绍、类和对象
  19. XSS CSS Cross SiteScript 跨站脚本攻击
  20. SpringMVC 源码阅读

热门文章

  1. shell 三剑客之 awk
  2. 最强U盘修复工具
  3. EditText设置输入的类型,只能输入纯数字,只能输入手机号码,只能输入邮箱等等。
  4. android开发之集成zxing,二维码,以及扫描二维码的功能实现。带源代码下载
  5. MonoBehaviour生命周期与对象数据池应用
  6. ThreadLocal是什么?谈谈你对他的理解
  7. vueRooter的总结
  8. 转载:[Oracle]杀死正在执行的sql语句
  9. 20190923-12Linux软件包管理 000 020
  10. docker打包项目