当前位置:网站首页>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;
}
}
}
边栏推荐
- 简单使用Lambda表达式
- Online tool for sorting multi-line strings
- 正则表达式-判断字符串是否匹配“AABB”模式
- 电学知识的疑问
- How to find package information and pin definitions for NXP S32K1xx series microcontrollers
- MYSQLg advanced ------ batch insert millions of data
- DDD 领域驱动设计
- BeautifulSoup4的介绍与使用
- 超顺磁四氧化三铁@二氧化硅@硫化镉纳米核壳结构材料|表面接枝mPEG的Fe3O4磁性纳米颗粒(f-Fe3O4)|相关产品
- Web APIs BOM- 操作浏览器:本地存储
猜你喜欢
SiO2 / KH550 modified ferroferric oxide nano magnetic particles | PDA package the ferromagnetic oxide nanoparticles (research)
Go lang1.18入门精炼教程——第一章:环境搭建
Fragments
IQ Products CMV Brite Turbo试剂盒的原理
MYSQL Advanced Chapter - Query Interception Analysis, Lock Mechanism, Master-Slave Replication
网络学习总结
什么是excel文件保护
代码目录结构
redis 运行lua 脚本 出现Invalid argument(s)
Unity backgammon game design and simple AI implementation (1)
随机推荐
Program Performance Analysis - Complexity Analysis
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
Polyamide-amine (PAMAM) dendrimer-bismuth sulfide composite nanoparticles | bismuth sulfide modified Gd‑DTPA‑OA ligand | for scientific research
代码目录结构
Introduction to AIOT
io.lettuce.core.RedisCommandTimeoutException Command timed out
单例模式
中英文说明书丨CalBioreagents ACTH N端单克隆抗体
tidb crash test
[HNOI2002]营业额统计
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
IQ Products CMV Brite Turbo试剂盒的原理
C# 利用iTextSharp画PDF
TCP segment of a reassembled PDU
Superparamagnetic iron [email protected]@cadmium sulfide nanocore-shell structure material|Fe3O4 magnetic nanop
Text String Length Sorting - Online Tool
【Feel】In the Unity Feel plugin, Camera cannot display CameraShake correctly
Regular Expression - Determine if a string matches the "AABB" pattern
Fe3O4/SiO2 Composite Magnetic Nanoparticles Aminated on SiO2-NH2/Fe3O4 Surface (Qiyue Reagent)
JMeter test - JMeter 】 【 upload multiple images/batch CSV file upload pictures interface parametric method