01 设计模式-创造型模式-工厂模式
-
工厂模式(Factory Pattern)是 Java 中最常用的设计模式之一,它提供了一种创建对象的方式,使得创建对象的过程与使用对象的过程分离。
-
工厂模式提供了一种创建对象的方式,而无需指定要创建的具体类。
-
通过使用工厂模式,可以将对象的创建逻辑封装在一个工厂类中,而不是在客户端代码中直接实例化对象,这样可以提高代码的可维护性和可扩展性。
设计模式,最近持续更新中,如需要请关注
如果你觉得我分享的内容或者我的努力对你有帮助,或者你只是想表达对我的支持和鼓励,请考虑给我点赞、评论、收藏。您的鼓励是我前进的动力,让我感到非常感激。
文章目录
- 1 概要
- 2 实现
- 3 Demo代码
- 4 开发案例
- 4.1 算法执行服务里,不同的任务数据来源不同,执行脚本类型不同,结果处理不同,使用工厂模式
- 4.2 网络还原时,不同的采集数据,解析处理方式不同
1 概要
意图
定义一个创建对象的接口,让其子类决定实例化哪一个具体的类。工厂模式使对象的创建过程延迟到子类。
主要解决
接口选择的问题。
何时使用
当我们需要在不同条件下创建不同实例时。
如何解决
通过让子类实现工厂接口,返回一个抽象的产品。
关键代码
对象的创建过程在子类中实现。
应用实例
- 汽车制造:你需要一辆汽车,只需从工厂提货,而不需要关心汽车的制造过程及其内部实现。
- Hibernate:更换数据库时,只需更改方言(Dialect)和数据库驱动(Driver),即可实现对不同数据库的切换。
优点
- 调用者只需要知道对象的名称即可创建对象。
- 扩展性高,如果需要增加新产品,只需扩展一个工厂类即可。
- 屏蔽了产品的具体实现,调用者只关心产品的接口。
缺点
每次增加一个产品时,都需要增加一个具体类和对应的工厂,使系统中类的数量成倍增加,增加了系统的复杂度和具体类的依赖。
使用场景
- 日志记录:日志可能记录到本地硬盘、系统事件、远程服务器等,用户可以选择记录日志的位置。
- 数据库访问:当用户不知道最终系统使用哪种数据库,或者数据库可能变化时。
- 连接服务器的框架设计:需要支持 “POP3”、“IMAP”、“HTTP” 三种协议,可以将这三种协议作为产品类,共同实现一个接口。
- 在算法执行服务中,每个任务需要处理的数据来源不同,根据数据类型创建对应的数据出来handle类,不用关心handle里的内部处理逻辑
注意事项
工厂模式适用于生成复杂对象的场景。如果对象较为简单,通过 new 即可完成创建,则不必使用工厂模式。使用工厂模式会引入一个工厂类,增加系统复杂度。
结构
工厂模式包含以下几个主要角色:
- 抽象产品(Abstract Product):定义了产品的共同接口或抽象类。它可以是具体产品类的父类或接口,规定了产品对象的共同方法。
- 具体产品(Concrete Product):实现了抽象产品接口,定义了具体产品的特定行为和属性。
- 抽象工厂(Abstract Factory):声明了创建产品的抽象方法,可以是接口或抽象类。它可以有多个方法用于创建不同类型的产品。
- 具体工厂(Concrete Factory):实现了抽象工厂接口,负责实际创建具体产品的对象。
2 实现
我们将创建一个 Shape 接口和实现 Shape 接口的实体类。下一步是定义工厂类 ShapeFactory。
FactoryPatternDemo 类使用 ShapeFactory 来获取 Shape 对象。它将向 ShapeFactory 传递信息(CIRCLE / RECTANGLE / SQUARE),以便获取它所需对象的类型。

3 Demo代码

Shape
/*** 公共接口*/
public interface Shape {void draw();
}
Circle
/*** 圆形,形状的实现类*/
public class Circle implements Shape {@Overridepublic void draw() {System.out.println("Inside Circle::draw() method.");}
}
Rectangle
/*** 矩形,形状的实现类*/
public class Rectangle implements Shape {@Overridepublic void draw() {System.out.println("Inside Rectangle::draw() method.");}
}
Square
/*** 方形,形状的实现类*/
public class Square implements Shape {@Overridepublic void draw() {System.out.println("Inside Square::draw() method.");}
}
ShapeFactory
/*** 形状工厂类【根据不同的参数创建对应的实例】*/
public class ShapeFactory {//使用 getShape 方法获取形状类型的对象public Shape getShape(String shapeType) {if (shapeType == null) {return null;}if (shapeType.equalsIgnoreCase("CIRCLE")) {return new Circle();} else if (shapeType.equalsIgnoreCase("RECTANGLE")) {return new Rectangle();} else if (shapeType.equalsIgnoreCase("SQUARE")) {return new Square();}return null;}
}
FactoryPatternDemo
/*** 总结:用来根据不同的参数创建对象*/
public class FactoryPatternDemo {public static void main(String[] args) {ShapeFactory shapeFactory = new ShapeFactory();//获取 Circle 的对象,并调用它的 draw 方法Shape shape1 = shapeFactory.getShape("CIRCLE");//调用 Circle 的 draw 方法shape1.draw();//获取 Rectangle 的对象,并调用它的 draw 方法Shape shape2 = shapeFactory.getShape("RECTANGLE");//调用 Rectangle 的 draw 方法shape2.draw();//获取 Square 的对象,并调用它的 draw 方法Shape shape3 = shapeFactory.getShape("SQUARE");//调用 Square 的 draw 方法shape3.draw();}
}
效果

4 开发案例
4.1 算法执行服务里,不同的任务数据来源不同,执行脚本类型不同,结果处理不同,使用工厂模式

说明:
- TaskAbstractFactory命名成抽象工厂,可以创建出来DataSetHandle工厂,ScriptExecuteHandle工厂,ResultHandle工厂,但是实现时,时间关系,简化成简单工厂模式。
- 工厂返回的对象,每次都是新创建出来的,因为这些handle每次创建初始化的参数是不同的,和下面的第二个案例有所不同

工厂类
/*** 任务抽象工厂类,创建各种处理类* @since 2023 -10-08 16:13*/
public class TaskAbstractFactory {private static final Logger LOGGER = LoggerFactory.getLogger(TaskAbstractFactory.class);/*** Gets script execute handle.** @param scriptParam the script param* @param algoId the algo id* @return the script execute handle*/public static ScriptExecuteHandle getScriptExecuteHandle(ScriptParam scriptParam, String algoId) {if (Constants.ScriptType.PYTHON.equals(scriptParam.getScriptType()) || Constants.ScriptType.PYTHON3.equals(scriptParam.getScriptType())) {return new PythonScriptExecuteHandle(scriptParam);} else {LOGGER.error("The algorithm type is not supported. algoId: {} ,scriptType: {} ", algoId,scriptParam.getScriptType());throw new CommonServiceException(AIModelError.ALGO_TYPE_NOT_SUPPORTED);}}/*** Gets data set handle list.** @param dataSets the data sets* @return the data set handle list*/public static List<DataSetHandle> getDataSetHandleList(List<InputDataSource> dataSets) {ArrayList<DataSetHandle> dataSetHandleList = new ArrayList<>(10);for (InputDataSource inputDataSource : dataSets) {dataSetHandleList.add(getDataSetHandle(inputDataSource));}return dataSetHandleList;}/*** Gets data set handle.** @param inputDataSource the input data source* @return the data set handle*/public static DataSetHandle getDataSetHandle(InputDataSource inputDataSource) {if (Constants.DataSourceType.MINIO_FILE.equalsIgnoreCase(inputDataSource.getDatatype())) {DataSetHandle dataSetHandle = new S3DataSetHandle(inputDataSource.getDataSourceInfo(),inputDataSource.getDataSourceConfig());// 进行数据源校验dataSetHandle.checkDataSource();return dataSetHandle;} else if (Constants.DataSourceType.HDFS_FILE.equalsIgnoreCase(inputDataSource.getDatatype())) {DataSetHandle dataSetHandle = new HdfsDataSetHandle(inputDataSource.getDataSourceInfo(),inputDataSource.getDataSourceConfig());// 进行数据源校验dataSetHandle.checkDataSource();return dataSetHandle;} else {LOGGER.error("The data source type is not supported. datatype: {} ", inputDataSource.getDatatype());throw new CommonServiceException(AIModelError.DATA_TYPE_NOT_SUPPORTED);}}/*** Gets result handle.** @param calculateParam the calculate param* @param scriptParam the script param* @return the result handle*/public static ResultHandle getResultHandle(CalculateParam calculateParam, ScriptParam scriptParam) {// 【预留】 设置结果集存放的数据源。目前所有的算法都有数据集,取数据集的第一个数据源作为结果上传的数据源OutputDataSource outputDataSource = getOutDataSource(calculateParam.getDataSets().get(0));if (Constants.CustomizedAlgoId.POTENTIAL_GUEST_ALGO_ID.equals(calculateParam.getAlgoId())) {// 定制化的处理方式,需要走特有的处理方式。此类算法,只能提前预置后return new PotentialGuestResultHandle(scriptParam, outputDataSource);} else {// 任务结果走默认处理方式,此类算法可以通过算法管理界面可以添加return new ResultHandle(scriptParam, outputDataSource);}}private static OutputDataSource getOutDataSource(InputDataSource inputDataSource) {return new OutputDataSource(inputDataSource.getDatatype(), inputDataSource.getDataSourceConfig());}}
使用
public TaskEntity(TaskInfo taskInfo, CalculateParam calculateParam, String algoPackDir, String localFileDir) {this.scriptParam = getScriptParam(calculateParam, algoPackDir, localFileDir);this.taskInfo = taskInfo;this.shellParamHandle = TaskAbstractFactory.getScriptExecuteHandle(scriptParam, calculateParam.getAlgoId());this.dataSetHandleList = TaskAbstractFactory.getDataSetHandleList(calculateParam.getDataSets());this.resultHandle = TaskAbstractFactory.getResultHandle(calculateParam, scriptParam);}
其他说明
设计是工厂创建实例的是子类,返回的是父类。多态的体现。同事父类有默认方法,子类是对父类的扩展, 或者重写。如下:
DataSetHandle
/*** 数据集处理父类* @since 2023 -09-15 15:35*/
public abstract class DataSetHandle {private static final Logger LOGGER = LoggerFactory.getLogger(DataSetHandle.class);/*** The Data source info.*/protected String dataSourceInfo;/*** The Data source config.*/protected String dataSourceConfig;/*** Instantiates a new Data set handle.** @param dataSourceInfo the data source info* @param dataSourceConfig the data source config*/public DataSetHandle(String dataSourceInfo, String dataSourceConfig) {this.dataSourceInfo = dataSourceInfo;this.dataSourceConfig = dataSourceConfig;}/*** Check data source.*/public void checkDataSource() {// 对参数的json格式进行校验if (!MyStringUtil.checkJson(dataSourceInfo)) {LOGGER.error("dataSourceInfo json format error.");throw new CommonServiceException(AIModelError.PARAM_ERROR, "dataSourceInfo json format error.");}if (StringUtils.isNotEmpty(dataSourceConfig) && !MyStringUtil.checkJson(dataSourceConfig)) {LOGGER.error("dataSourceConfig json format error.");throw new CommonServiceException(AIModelError.PARAM_ERROR, "dataSourceConfig json format error.");}}/*** Handle data.** @param taskId the task id* @param localFileDir the local file dir*/public abstract void handleData(String taskId, String localFileDir);}
S3DataSetHandle
/*** S3或者minio类型的数据集处理类* @since 2023 -09-15 15:35*/
public class S3DataSetHandle extends DataSetHandle {private static final Logger LOGGER = LoggerFactory.getLogger(S3DataSetHandle.class);/*** Instantiates a new S 3 data set handle.** @param dataSourceInfo the data source info* @param dataSourceConfig the data source config*/public S3DataSetHandle(String dataSourceInfo, String dataSourceConfig) {super(dataSourceInfo, dataSourceConfig);}/*** Check data source.*/@Overridepublic void checkDataSource() {// 1 父类进行参数json格式的校验super.checkDataSource();// 2 具体子类,进行特性校验List<S3DataSourceInfo> s3DataSourceList = JSON.parseArray(dataSourceInfo, S3DataSourceInfo.class);for (S3DataSourceInfo s3DataSource : s3DataSourceList) {// 目前S3,仅支持zip文件if (!Constants.FileType.ZIP.equalsIgnoreCase(s3DataSource.getFileType())) {LOGGER.error("The file type is not supported. fileType:{}", s3DataSource.getFileType());throw new CommonServiceException(AIModelError.PARAM_ERROR,"The file type is not supported. fileType: " + s3DataSource.getFileType());}if (StringUtils.isEmpty(s3DataSource.getFileId()) || StringUtils.isEmpty(s3DataSource.getStoreDirName())) {LOGGER.error("fileId and storeDirName cannot be empty.");throw new CommonServiceException(AIModelError.PARAM_ERROR, "fileId and storeDirName cannot be empty.");}}}/*** Handle data.** @param taskId the task id* @param localFileDir the local file dir*/@Overridepublic void handleData(String taskId, String localFileDir) {// 1 获取配置S3DataSourceConfig s3DataSourceConfig = JSON.parseObject(dataSourceConfig, S3DataSourceConfig.class);// 2 初始化S3客户端S3ClientUtils s3ClientUtils = S3ClientUtils.getInstance(s3DataSourceConfig);for (S3DataSourceInfo s3DataSourceInfo : JSON.parseArray(dataSourceInfo, S3DataSourceInfo.class)) {InputStream s3InputStream = null;try {// 3 获取数据流s3InputStream = s3ClientUtils.download(s3DataSourceConfig.getBucketName(),s3DataSourceInfo.getFileId());// 4 将文件保存在本地磁盘saveFileToLocal(s3InputStream, s3DataSourceInfo, taskId, localFileDir + taskId);} finally {MyIOUtils.closeInputStream(s3InputStream);}}}
}
4.2 网络还原时,不同的采集数据,解析处理方式不同
说明:
- 创建对象由spring类管理,创建出来的对象是单例的,这个案例1有所不同,案例1,每个类初始化的参数不同。这个案例对象初始化方式一样,只是处理逻辑不同。
- 在vimpim对象是,因为参数不同所有每次都需要new
工厂类:
/*** The type Ods process factory.** @since 2024 -06-11 10:54*/
@Slf4j
@Service
public class OdsProcessFactory {private static final List<VimPimModelDto> VIM_PIM_MODEL_V2_LIST = new ArrayList<>();private static final String VIM_PIM_MODEL_V2_FILE_PATH = "2.json";private static final List<String> VIM_PIM_MODEL_V2_WHITE_LIST = Arrays.asList();private static final List<VimPimModelDto> VIM_PIM_MODEL_V3_LIST = new ArrayList<>();private static final String VIM_PIM_MODEL_V3_FILE_PATH = "3.json";private static final List<String> VIM_PIM_MODEL_V3_WHITE_LIST = Arrays.asList();/*** The Data source.*/@Resource(name = "gauss")DataSource dataSource;@Autowiredprivate VimPimRepository vimPimRepository;@Autowiredprivate VnfMaeCnDataProcessDomainService vnfMaeCnDataProcessDomainService;@Autowiredprivate VnflocLcmDataProcessDomainService vnflocLcmDataProcessDomainService;static {// 初始化模型数据initModel(VIM_PIM_MODEL_V2_FILE_PATH, VIM_PIM_MODEL_V2_WHITE_LIST, VIM_PIM_MODEL_V2_LIST);initModel(VIM_PIM_MODEL_V3_FILE_PATH, VIM_PIM_MODEL_V3_WHITE_LIST, VIM_PIM_MODEL_V3_LIST);}private static void initModel(String vimPimModelFilePath, List<String> vimPimModelWhiteList,List<VimPimModelDto> vimPimModelList) {}/*** Gets ods process service.** @param taskDto the task dto* @param dataFormat the data format* @return the ods process service*/public DataProcessDomainService getOdsProcessService(CollectionTaskDto taskDto, int dataFormat) {if (OdsParseConstants.OdsDataFormat.VNF_MAECN == dataFormat|| OdsParseConstants.OdsDataFormat.NIC_DSP == dataFormat) {return vnfMaeCnDataProcessDomainService;} else if (OdsParseConstants.OdsDataFormat.VIM_OV2 == dataFormat|| OdsParseConstants.OdsDataFormat.PIM_OV2 == dataFormat) {return getVimPimDataProcessV2DomainService();} else if (OdsParseConstants.OdsDataFormat.VIM_OV3 == dataFormat|| OdsParseConstants.OdsDataFormat.PIM_OV3 == dataFormat) {return getVimPimDataProcessV3DomainService();} else if (OdsParseConstants.OdsDataFormat.VNFLOC_LCM == dataFormat) {return vnflocLcmDataProcessDomainService;} else {// 采集来的数据格式不支持log.warn("Incorrect data dataFormat. taskId:{}, tasksSn:{}, dataFormat:{} ", taskDto.getTaskId(),taskDto.getTaskSn(), dataFormat);}return null;}public VimPimDataProcessV2DomainService getVimPimDataProcessV2DomainService() {return new VimPimDataProcessV2DomainService(VIM_PIM_MODEL_V2_LIST, dataSource, vimPimRepository);}public VimPimDataProcessV3DomainService getVimPimDataProcessV3DomainService() {return new VimPimDataProcessV3DomainService(VIM_PIM_MODEL_V3_LIST, dataSource, vimPimRepository);}
}

相关文章:
01 设计模式-创造型模式-工厂模式
工厂模式(Factory Pattern)是 Java 中最常用的设计模式之一,它提供了一种创建对象的方式,使得创建对象的过程与使用对象的过程分离。 工厂模式提供了一种创建对象的方式,而无需指定要创建的具体类。 通过使用工厂模式…...
ComnandLineRunner接口, ApplcationRunner接口
ComnandLineRunner接口, ApplcationRunner接口 介绍: 这两个接口都有一个run方法,执行时间在容器对象创建好后,自动执行run ( )方法。 创建容器的同时会创建容器中的对象,同时会把容器中的对象的属性赋上值: 举例&…...
Swift用于将String拆分为数组的components与split的区别
根据特定分隔符拆分字符串 在 Swift 中,components(separatedBy:) 和 split(separator:) 都可以用于将字符串拆分为数组,但它们有一些关键区别。下面将从返回值类型、性能和功能等角度进行对比。 1. 返回值类型 components(separatedBy:):…...
docker之redis安装(项目部署准备)
创建网络 docker network create net-ry --subnet172.68.0.0/16 --gateway172.68.0.1 redis安装 #创建目录 mkdir -p /data/redis/{conf,data} #上传redis.conf文件到/data/redis/conf文件夹中 #对redis.conf文件修改 # bind 0.0.0.0 充许任何主机访问 # daemonize no #密码 # …...
使用Maven前的简单准备
目录 一、Maven的准备 1、安装jdk1.8或以上版本 2、下载Maven 3、安装Maven 二、Maven目录的分析 三、Maven的环境变量配置 1、设置MAVEN_HOME环境变量 2、设置Path环境变量 3、验证配置是否完成 一、Maven的准备 1、安装jdk1.8或以上版本 jdk的安装 2、下载Maven…...
Java | Leetcode Java题解之第494题目标和
题目: 题解: class Solution {public int findTargetSumWays(int[] nums, int target) {int sum 0;for (int num : nums) {sum num;}int diff sum - target;if (diff < 0 || diff % 2 ! 0) {return 0;}int neg diff / 2;int[] dp new int[neg …...
阅读笔记 Contemporary strategy analysis Chapter 13
来源:Robert M. Grant - Contemporary strategy analysis (2018) Chapter 13 Implementing Corporate Strategy: Managing the Multibusiness Firm Ⅰ Introduction and Objectives 多业务公司 multibusiness firm由多个独立的业务部门组成,如业务单元…...
Python GUI 编程:tkinter 初学者入门指南——复选框
在本文中,将介绍 tkinter Checkbox 复选框小部件以及如何有效地使用它。 复选框是一个允许选中和取消选中的小部件。复选框可以保存一个值,通常,当希望让用户在两个值之间进行选择时,可以使用复选框。 要创建复选框,…...
使用vscode导入库失败解决方法
导入库失败原因 在使用vscode写python代码时,有时会遇见导入库失败的情况,如下图:无法解析导入“xxxxx” 或者 运行时报错:ModuleNotFoundError: No module named xxxxx。 原因可能有: 根本没有下载库;…...
无线网卡知识的学习-- mac80211主要代码流程
一 简介概要: mac80211驱动程序作为Linux内核中管理和控制无线网络接口的核心模块,其主要流程涵盖了从数据帧接收到发送的完整过程。 主要覆盖了7个方面: 1. 数据帧接收流程,2. 数据帧发送流程 3. 频道管理和切换 4. 接口管理 5. 安全和认证 6. 管理和调试 7. 注册和初…...
关于k8s集群高可用性的探究
1. k8s的高可用的核心是什么? 说到核心、本质 意味着要从物理层来考虑技术 k8s是一个容器编排管理工具,k8s受欢迎的时机 是docker容器受欢迎时,因为太多的docker容器,管理起来是一个大工程 那么刚好k8s是google自己用了十来年…...
保姆级Pinpoint(APM)实战教程
什么是Pinpoint Pinpoint是由韩国NAVER公司开发并开源的一款应用程序管理工具,主要针对大规模分布式系统进行性能监控和故障诊断。通过跟踪分布式应用程序之间的事务,帮助分析系统的整体结构以及其中的组件是如何相互连接的。 与其对标的还有Twitter的Zi…...
使用SpringBoot自定义注解+AOP+redisson锁来实现防接口幂等性重复提交
1 前提,整合好springboot和redis,redisson的环境 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId> </dependency> 2 编写自定义注解,注解的作用是标记…...
k8s和ipvs、lvs、ipvsadm,iptables,底层梳理,具体是如何实现的
计算节点的功能: 提供容器运行的环境 kube-proxy的主要功能: 术业有专攻, kube-proxy的主要功能可以概括为4个字 网络规则 那么kube-proxy自己其实是个daemonset控制器跑的 每个节点上都有个的pod 它负责网络规则 其实呢 它还是个小…...
三、归一化与标准化
归一化与标准化 前言一、最小最大值归一化1.1 原理(公式)1.2 API 介绍1.2.1 参数介绍1.2.2 属性介绍1.2.3 注意事项1.2.4 代码演示 1.3 举例说明 二、标准化2.1 原理(公式)2.2 API 介绍2.2.1 参数介绍2.2.2 属性介绍2.2.3 注意事项…...
B2105 矩阵乘法
B2105 矩阵乘法 #include <iostream> using namespace std; int main(){int n,m,k;cin>>n>>m>>k;int arr1[n][m];int arr2[m][k];for(auto & line:arr1){for(auto & x: line){cin>>x;}}for(auto & line:arr2){for(auto & x: lin…...
centos之下的mysql8的安装
文章目录 1.mysql.com进入(网址栏)2.xshell操作2.1拖拽上传2.2安装发布包2.3检查情况2.4安装mysql2.5手动启动2.6查看状态2.7查看随机密码2.8登录2.9重置密码 1.mysql.com进入(网址栏) 找下面的这个download按钮: 一直往下面划:找到下面的这个 下面的这个…...
计算机导论
概述 计算机简史 1935年代,英国数学家图灵(Alan Turing)提出“图灵机”,奠定了计算机的理论基础。 1952年,冯诺依曼确定了计算机由运算器、控制器、存储器、输入、输出等5部分组成(Von Neumann 体系结构)。 60年代…...
力扣209-长度最小的子数组-滑动窗口思想
题目 给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其总和大于等于 target 的长度最小的 子数组 [numsl, numsl1, ..., numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回 0 。 示例 1: 输入&am…...
Xilinx 7系列FPGA PCI Express IP核简介
前言:Xilinx7系列FPGA集成了新一代PCI Express集成块,支持8.0Gb/s数据速率的PCI Express 3.0。本文介绍了7系列FPGA PCIe Gen3的应用接口及一些特性。 1. PCI Express规范演进 PCIe是一种高速串行计算机扩展总线标准,旨在替代传统的PCI和AG…...
Leetcode 3577. Count the Number of Computer Unlocking Permutations
Leetcode 3577. Count the Number of Computer Unlocking Permutations 1. 解题思路2. 代码实现 题目链接:3577. Count the Number of Computer Unlocking Permutations 1. 解题思路 这一题其实就是一个脑筋急转弯,要想要能够将所有的电脑解锁&#x…...
cf2117E
原题链接:https://codeforces.com/contest/2117/problem/E 题目背景: 给定两个数组a,b,可以执行多次以下操作:选择 i (1 < i < n - 1),并设置 或,也可以在执行上述操作前执行一次删除任意 和 。求…...
基于数字孪生的水厂可视化平台建设:架构与实践
分享大纲: 1、数字孪生水厂可视化平台建设背景 2、数字孪生水厂可视化平台建设架构 3、数字孪生水厂可视化平台建设成效 近几年,数字孪生水厂的建设开展的如火如荼。作为提升水厂管理效率、优化资源的调度手段,基于数字孪生的水厂可视化平台的…...
在web-view 加载的本地及远程HTML中调用uniapp的API及网页和vue页面是如何通讯的?
uni-app 中 Web-view 与 Vue 页面的通讯机制详解 一、Web-view 简介 Web-view 是 uni-app 提供的一个重要组件,用于在原生应用中加载 HTML 页面: 支持加载本地 HTML 文件支持加载远程 HTML 页面实现 Web 与原生的双向通讯可用于嵌入第三方网页或 H5 应…...
微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据
微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据 Power Query 具有大量专门帮助您清理和准备数据以供分析的功能。 您将了解如何简化复杂模型、更改数据类型、重命名对象和透视数据。 您还将了解如何分析列,以便知晓哪些列包含有价值的数据,…...
C#学习第29天:表达式树(Expression Trees)
目录 什么是表达式树? 核心概念 1.表达式树的构建 2. 表达式树与Lambda表达式 3.解析和访问表达式树 4.动态条件查询 表达式树的优势 1.动态构建查询 2.LINQ 提供程序支持: 3.性能优化 4.元数据处理 5.代码转换和重写 适用场景 代码复杂性…...
【LeetCode】算法详解#6 ---除自身以外数组的乘积
1.题目介绍 给定一个整数数组 nums,返回 数组 answer ,其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法,且在 O…...
MyBatis中关于缓存的理解
MyBatis缓存 MyBatis系统当中默认定义两级缓存:一级缓存、二级缓存 默认情况下,只有一级缓存开启(sqlSession级别的缓存)二级缓存需要手动开启配置,需要局域namespace级别的缓存 一级缓存(本地缓存&#…...
CSS3相关知识点
CSS3相关知识点 CSS3私有前缀私有前缀私有前缀存在的意义常见浏览器的私有前缀 CSS3基本语法CSS3 新增长度单位CSS3 新增颜色设置方式CSS3 新增选择器CSS3 新增盒模型相关属性box-sizing 怪异盒模型resize调整盒子大小box-shadow 盒子阴影opacity 不透明度 CSS3 新增背景属性ba…...
字符串哈希+KMP
P10468 兔子与兔子 #include<bits/stdc.h> using namespace std; typedef unsigned long long ull; const int N 1000010; ull a[N], pw[N]; int n; ull gethash(int l, int r){return a[r] - a[l - 1] * pw[r - l 1]; } signed main(){ios::sync_with_stdio(false), …...
