当前位置:网站首页>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;
}
}
}
边栏推荐
- Bismuth sulfide nanorods with CT imaging function | Bismuth sulfide-zinc protoporphyrin composites (PAMAM/Bi2S3 composite nanoparticles)
- Domain name batch query online tool
- db.sqlite3没有“as Data Source“解决方法
- 按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
- vs番茄助手的方便功能和便捷快捷键介绍
- io.lettuce.core.RedisCommandTimeoutException Command timed out
- C语言实现顺序栈和链队列
- 中英文说明书丨TRC D-阿卓糖(D-Altrose)
- Excel受保护的工作表怎么操作?
- The solution that does not work and does not take effect after VScode installs ESlint
猜你喜欢
力扣刷题180
缓存技术使用
DevNet: Deviation Aware Networkfor Lane Detection
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
Output method of list string print(*a) print(““.join(str(c) for c in a) )
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
GNNExplainer applied to node classification task
输入框最前面添加放大镜&&background-image和background-color冲突问题
Molybdenum disulfide/hafnium dioxide composite nanomaterials (MoS2/HfO2) | tantalum-doped hafnium dioxide nanoparticles (Qi Yue bio)
mongo+ycsb性能测试及线程数分析
随机推荐
Fe3O4/SiO2 Composite Magnetic Nanoparticles Aminated on SiO2-NH2/Fe3O4 Surface (Qiyue Reagent)
idea中PlantUML插件使用
C language implements sequential stack and chain queue
Excel受保护的工作表怎么操作?
多行字符串排序在线工具
Use of PlantUML plugin in idea
excel表格如何不需鼠标往下拖动而自动往下填
sql problem solving statement to create a table
Can Jincang Database Set Transaction Automatic Commit?
db.sqlite3没有“as Data Source“解决方法
逆向工程
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
网络学习总结
qt send mail program
语句加锁分析
GNNExplainer应用于节点分类任务
【R语言】把文件夹下的所有文件提取到特定文件夹
中英文说明书丨TRC 交替醇(Catalogue NumberA575760)
电学知识的疑问
mmdetection源码解析--ResNet18