当前位置:网站首页>Simple Factory Pattern
Simple Factory Pattern
2022-08-09 06:28:00 【The koala over rice】
简单工厂模式
From simple plant role(创造者),抽象产品(所有具体产品的父类,可以是接口或者抽象类),具体产品(Succession or implement specific products)三个组成
具体实现
public class Test {
// 相当于客户端
public static void main(String[] args) {
// 首先创建工厂,Through the factory to create the corresponding class again
Factory factory = new Factory();
factory.getCar("wulin").name();
factory.getCar("dazong").name();
}
// 抽象产品
interface Car {
void name();
}
// 具体产品
static class Dazong implements Car {
@Override
public void name() {
System.out.println("this is dazong");
}
}
// 具体产品
static class Wulin implements Car {
@Override
public void name() {
System.out.println("this is wulin");
}
}
// 简单工厂
static class Factory {
// By calling the factory get entity method to create specific products,Return to the abstract specific products
public Car getCar(String car){
switch (car){
case "wulin":
return new Wulin();
case "dazong":
return new Dazong();
}
return null;
}
}
}
边栏推荐
- mmdetection源码解析--ResNet18
- 思维方法 解决问题的能力
- 常用Oracle命令
- 缓存技术使用
- [MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
- 磁性核壳四氧化三铁颗粒负载金纳米星|磁性Fe3O4-POSS-COOH|超顺磁四氧化三铁聚多巴胺核壳结构纳米粒子
- 数据库中间件-jdbi
- C语言实现顺序栈和链队列
- 线程的6种状态
- Text String Length Sorting - Online Tool
猜你喜欢
随机推荐
像天才一样思考:如何培养自己的创造力?
报错jinja2.exceptions.UndefinedError: ‘form‘ is undefined
PDF不能打印和复制的问题如何解决?
After the VB.net program is closed, the background is still connected to SQL
VS2019 common shortcut keys
单例模式
ZIP压缩包文件删除密码的方法
Error: flask: TypeError: 'function' object is not iterable
半胱氨酸/半乳糖/苝二酰亚胺功能化Fe3O4四氧化三铁纳米材料|科研试剂
flask创建数据库失败未报错
How to find package information and pin definitions for NXP S32K1xx series microcontrollers
Likou Brush Question 180
install flask
Domain name batch query online tool
jdepend
idea中PlantUML插件使用
vs番茄助手的方便功能和便捷快捷键介绍
运放-运算放大器经典应用电路大全-应用电路大全
力扣刷题180
qt send mail program