当前位置:网站首页>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;
}
}
}
边栏推荐
- 使用百度EasyDL实现智能垃圾箱
- 带头双向循环链表的增删查改(C语言实现)
- Xilinx Zynq ZynqMP DNA
- 中英文说明书丨CalBioreagents ACTH N端单克隆抗体
- 报错jinja2.exceptions.UndefinedError: ‘form‘ is undefined
- Domain name batch query online tool
- Program Performance Analysis - Complexity Analysis
- 关于如何查找NXP S32K1xx系列单片机的封装信息和引脚定义
- Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
- Output method of list string print(*a) print(““.join(str(c) for c in a) )
猜你喜欢

运算放大器(OPA)超详细参数讲解-运放---以及8个型号的运算放大器分析对比

GNNExplainer applied to node classification task

Use of PlantUML plugin in idea

使用百度EasyDL实现智能垃圾箱

sql问题解答创建表的语句

按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程

db.sqlite3没有“as Data Source“解决方法

How to find package information and pin definitions for NXP S32K1xx series microcontrollers

运放-运算放大器经典应用电路大全-应用电路大全

Getting started with kubernetes apparmor
随机推荐
phpstudy 安装 flarum论坛
[GO], arrays and slices
Unity 五子棋游戏设计和简单AI(3)
中英文说明书丨CalBioreagents 山羊抗人白蛋白,IgG组分
IQ Products CMV Brite Turbo试剂盒的原理
治疗消化性溃疡—Toronto Research Chemicals 甘氨酸铝
MYSQL Advanced Chapter - Query Interception Analysis, Lock Mechanism, Master-Slave Replication
jdepend
GNNExplainer应用于节点分类任务
static静态关键字和继承
Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
Service
phpstudy install flarum forum
idea中PlantUML插件使用
报错:flask: TypeError: ‘function‘ object is not iterable
Initials-Letter Query Tool-Word Abbreviation Query Online Tool
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
MYSQLg advanced ------ batch insert millions of data
默默重新开始,第一页也是新的一页