package 工厂方法模式;
来源:互联网 发布:公安大数据宣传片 编辑:程序博客网 时间:2024/06/06 01:01
package 工厂方法模式;
interface Fruit {
public void show();
}
class Banana implements Fruit {
public void show() {
System.out.println("我是香蕉");
}
}
class Apple implements Fruit {
public void show() {
System.out.println("我是苹果");
}
}
interface FruitFactory {
public Fruit getInstance();
}
class AppleFactory implements FruitFactory {
private Apple apple = new Apple();
public Fruit getInstance() {
return apple;
}
}
class BananaFactory implements FruitFactory {
private Banana banana = new Banana();
public Fruit getInstance() {
return banana;
}
}
public class FactoryMethod {
public static void main(String[] args) {
System.out.println("工厂方法模式");
AppleFactory afAppleFactory = new AppleFactory();
Fruit apple = afAppleFactory.getInstance();
apple.show();
}
}
interface Fruit {
public void show();
}
class Banana implements Fruit {
public void show() {
System.out.println("我是香蕉");
}
}
class Apple implements Fruit {
public void show() {
System.out.println("我是苹果");
}
}
interface FruitFactory {
public Fruit getInstance();
}
class AppleFactory implements FruitFactory {
private Apple apple = new Apple();
public Fruit getInstance() {
return apple;
}
}
class BananaFactory implements FruitFactory {
private Banana banana = new Banana();
public Fruit getInstance() {
return banana;
}
}
public class FactoryMethod {
public static void main(String[] args) {
System.out.println("工厂方法模式");
AppleFactory afAppleFactory = new AppleFactory();
Fruit apple = afAppleFactory.getInstance();
apple.show();
}
}
0 0
- package 工厂方法模式;
- 工厂模式 -- 工厂方法
- 工厂模式-工厂方法
- 工厂模式-工厂方法
- 工厂 > 工厂方法模式
- 工厂模式-工厂方法模式
- 工厂模式-工厂方法模式
- 工厂模式---工厂方法模式
- 【模式】工厂方法模式
- 工厂方法,抽象工厂模式
- C#工厂模式-工厂方法
- 工厂模式 和工厂方法
- 工厂模式-C-工厂方法
- 工厂模式以及工厂方法
- 简单工厂、工厂方法、抽象工厂模式
- 简单工厂、工厂方法、抽象工厂模式
- 工厂模式(简单工厂、工厂方法)
- 简单工厂|工厂方法|抽象工厂模式
- 6--OOP
- 总结35
- 译文:使用MVC5的Entity Framework 6入门(六)——为ASP.NET MVC应用程序创建更复杂的数据模型
- 进制转换
- 用数据库实现通讯录
- package 工厂方法模式;
- 【CodeVS 2083】Cryptcowgraphy 解密牛语
- lightoj 1029 生成树裸题
- 苏嵌第二天
- 求两个整数的最小公倍数和最大公约数的算法及其C++实现
- 解决关于那些文件夹Unity可以发布出去的问题
- Docker Container同时启动多服务 centOS6
- 8. 大型网站架构演化
- OllyDBG 入门系列<1> 认识OllyDBG