建造者模式

CSV文件输入到simulink中 将示波器波形和数据CSV文件保存下来进行数据分析。将波形绘制到simulink中 阅读详情

建造者模式是将对象的构建封装起来解耦,方便调用者创建复杂的对象,无需知道构建的细节。

常见的使用场景就是一些复杂的连接对象,有非常多的配置,用户不可能清楚每一个属性,所以一般会通过建造者模式来提供属性的默认值,用户只需设置关键的属性,方便调用者使用。

在这里插入图片描述

下面根据nacos源码里的一个例子说明建造者模式

@Data
public class RestResult<T> implements Serializable {

    private static final long serialVersionUID = 6095433538316185017L;

    private int code;

    private String message;

    private T data;

    public RestResult() {
    }

    public RestResult(int code, String message, T data) {
        this.code = code;
        this.setMessage(message);
        this.data = data;
    }

    public RestResult(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public RestResult(int code, String message) {
        this.code = code;
        this.setMessage(message);
    }

    public boolean ok() {
        return this.code == 0 || this.code == 200;
    }

    /**
     * 这里有一些简化,没有继承父类或接口,建造者模式实际可以有不同的实现子类
     */
    public static <T> ResResultBuilder<T> builder() {
        return new ResResultBuilder<T>();
    }

    public static final class ResResultBuilder<T> {

        private int code;

        private String errMsg;

        private T data;

        private ResResultBuilder() {
        }

        public ResResultBuilder<T> withCode(int code) {
            // 当然这里可以再添加一些复杂的逻辑,比如设置了某属性值,其他属性就只能为某些值
            this.code = code;
            return this;
        }

        public ResResultBuilder<T> withMsg(String errMsg) {
            this.errMsg = errMsg;
            return this;
        }

        public ResResultBuilder<T> withData(T data) {
            this.data = data;
            return this;
        }

        /**
         * Build result.
         *
         * @return result
         */
        public RestResult<T> build() {
            RestResult<T> restResult = new RestResult<T>();
            restResult.setCode(code);
            restResult.setMessage(errMsg);
            restResult.setData(data);
            return restResult;
        }
    }
}

下面相当于Director,用于指挥控制对象的创建

public class RestResultUtils {
    
    public static <T> RestResult<T> success() {
        return RestResult.<T>builder().withCode(200).build();
    }
    
    public static <T> RestResult<T> success(T data) {
        return RestResult.<T>builder().withCode(200).withData(data).build();
    }
    
    public static <T> RestResult<T> success(int code, T data) {
        return RestResult.<T>builder().withCode(code).withData(data).build();
    }
    
    public static <T> RestResult<T> failed() {
        return RestResult.<T>builder().withCode(500).build();
    }
    
    public static <T> RestResult<T> failed(int code, T data) {
        return RestResult.<T>builder().withCode(code).withData(data).build();
    }
    
}

应用举例

经常用来提供那些拥有复杂属性的对象,用户可以只设置自己关心的部分属性,如spring框架提供的很多连接对象。

下面拿构建RedisCacheManager的源码举例:

 @Bean
 RedisCacheManager redisCacheManager() {
 	 // 我们使用时只需要设置关键的属性即可
 	 return RedisCacheManager.RedisCacheManagerBuilder
 	 		.fromConnectionFactory(lettuceConnectionFactory)
            .withInitialCacheConfigurations(cacheConfigurationMap)
            .disableCreateOnMissingCache()
            .build();
 }

这里其实也是用到了建造者模式,

public class RedisCacheManager{

    private final RedisCacheWriter cacheWriter;
    private final RedisCacheConfiguration defaultCacheConfig;
    private final Map<String, RedisCacheConfiguration> initialCacheConfiguration;
    private final boolean allowInFlightCacheCreation;

 
    private RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
                              boolean allowInFlightCacheCreation) {

        Assert.notNull(cacheWriter, "CacheWriter must not be null!");
        Assert.notNull(defaultCacheConfiguration, "DefaultCacheConfiguration must not be null!");

        this.cacheWriter = cacheWriter;
        this.defaultCacheConfig = defaultCacheConfiguration;
        this.initialCacheConfiguration = new LinkedHashMap<>();
        this.allowInFlightCacheCreation = allowInFlightCacheCreation;
    }

    protected RedisCache createRedisCache(String name, @Nullable RedisCacheConfiguration cacheConfig) {
        return new RedisCache(name, cacheWriter, cacheConfig != null ? cacheConfig : defaultCacheConfig);
    }

  	// 通过builder来设置RedisCacheManager属性
    public static class RedisCacheManagerBuilder {

        private RedisCacheWriter cacheWriter;
        private RedisCacheConfiguration defaultCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
        private final Map<String, RedisCacheConfiguration> initialCaches = new LinkedHashMap<>();
        private boolean enableTransactions;
        boolean allowInFlightCacheCreation = true;

        private RedisCacheManagerBuilder() {}

        private RedisCacheManagerBuilder(RedisCacheWriter cacheWriter) {
            this.cacheWriter = cacheWriter;
        }

        public static RedisCacheManagerBuilder fromConnectionFactory(RedisConnectionFactory connectionFactory) {
            return new RedisCacheManagerBuilder(new DefaultRedisCacheWriter(connectionFactory));
        }

        public static RedisCacheManagerBuilder fromCacheWriter(RedisCacheWriter cacheWriter) {
            return new RedisCacheManagerBuilder(cacheWriter);
        }

        public RedisCacheManagerBuilder cacheDefaults(RedisCacheConfiguration defaultCacheConfiguration) {
            Assert.notNull(defaultCacheConfiguration, "DefaultCacheConfiguration must not be null!");
            this.defaultCacheConfiguration = defaultCacheConfiguration;
            return this;
        }

        public RedisCacheManagerBuilder transactionAware() {
            this.enableTransactions = true;
            return this;
        }
   
        public RedisCacheManagerBuilder initialCacheNames(Set<String> cacheNames) {
            Assert.notNull(cacheNames, "CacheNames must not be null!");
            cacheNames.forEach(it -> withCacheConfiguration(it, defaultCacheConfiguration));
            return this;
        }

        public RedisCacheManagerBuilder withInitialCacheConfigurations(
            Map<String, RedisCacheConfiguration> cacheConfigurations) {
            Assert.notNull(cacheConfigurations, "CacheConfigurations must not be null!");
            cacheConfigurations.forEach((cacheName, configuration) -> Assert.notNull(configuration,
                String.format("RedisCacheConfiguration for cache %s must not be null!", cacheName)));
            this.initialCaches.putAll(cacheConfigurations);
            return this;
        }

        public RedisCacheManagerBuilder withCacheConfiguration(String cacheName, RedisCacheConfiguration cacheConfiguration) {
            Assert.notNull(cacheName, "CacheName must not be null!");
            Assert.notNull(cacheConfiguration, "CacheConfiguration must not be null!");
            this.initialCaches.put(cacheName, cacheConfiguration);
            return this;
        }
     
        public RedisCacheManagerBuilder disableCreateOnMissingCache() {
            this.allowInFlightCacheCreation = false;
            return this;
        } }

        public RedisCacheManager build() {
            Assert.state(cacheWriter != null, "CacheWriter must not be null! '.");
            RedisCacheManager cm = new RedisCacheManager(cacheWriter, defaultCacheConfiguration, initialCaches, allowInFlightCacheCreation);
            cm.setTransactionAware(enableTransactions);
            return cm;
        }
    }
}

优点

  • 易于解耦
    将产品本身与产品创建过程进行解耦,可以使用相同的创建过程来得到不同属性的产品。
  • 易于精确控制对象的创建
    将复杂产品的创建步骤分解在不同的方法中,使得创建过程更加清晰
  • 易于拓展
    增加新的具体建造者无需修改原有类库的代码,易于拓展,符合“开闭原则“。

每一个具体建造者都相对独立,而与其他的具体建造者无关,因此可以很方便地替换具体建造者或增加新的具体建造者,用户使用不同的具体建造者即可得到不同的产品对象。

缺点

  • 建造者模式所创建的产品一般具有较多的共同点,其组成部分相似;如果产品之间的属性差异性很大,则不适合使用建造者模式。
  • 如果产品的内部变化复杂,可能会导致需要定义很多具体建造者类来实现这种变化,导致系统变得很庞大
Probability and Statistics - 4th edition 立即下载

相关推荐

从SC7A20数据手册到代码:一步步搞定加速度值读取与换算(避坑指南)

本文详细解析了SC7A20三轴加速度传感器的数据手册,从寄存器配置到原始数据读取,再到加速度值的换算方法。通过代码示例和避坑指南,帮助开发者准确实现加速度值的读取与换算,适用于嵌入式开发和运动检测应用。

weixin_26878995的博客 582

缓存抽象层Spring cache实战操作

Spring缓存抽象 Spring从3.1开始定义了一系列抽象接口来统一不同的缓存技术;并支持使用JCache(JSR-107)注解简化我们进行缓存开发。Spring Cache 只负责维护抽象层,具体的实现由你的技术选型来决定。将缓存处理和缓存技术解除耦合。 依赖引入 Spring cache 抽象由spring-context相关组件实现。非Spring Boot 项目可通过引入该模块进行集...

码农小胖哥 1850

(MIUI)小米手机录音文件深度寻踪:从系统缓存到数据目录的实战解析

本文深入解析了MIUI系统中录音文件丢失的常见原因及解决方案,包括系统升级兼容性问题、应用缓存机制异常和存储权限变动。通过实战操作指南,详细介绍了如何从系统目录、数据库层面恢复录音文件,并提供了预防措施和自动化备份方案,帮助小米手机用户有效找回重要录音数据。

weixin_42699679的博客 515

spring-boot-redis

简介 ​ Spring Data Redis是spring基于Redis做的一些模块化功能,属于spring全家桶其中之一,spring-data-redis提供了redis操作的封装和实现;RedisTemplate模板类封装了redis连接池管理的逻辑,业务代码无须关心获取,释放连接逻辑;spring redis同时支持了Jedis,Jredis,rjc 客户端操作; 概念 首先须要了解几个具...

qq_43582091的博客 454

48V电气架构全面科普和解析:下一代智能电动汽车核心驱动

随着电动汽车(EV)技术的不断发展,传统的12V电力系统已经逐渐无法满足日益增长的功率需求,尤其是在电动汽车中,48V电气系统的引入成为了一种理想的解决方案。在电动汽车中,48V系统与Zonal架构的结合,不仅有效提升了车辆电力系统的能效,还为未来的技术升级提供了灵活的设计基础。随着电动汽车(EV)技术的发展,车辆电气系统的工作电压逐步从传统的12V系统向更高的电压过渡。随着电动汽车技术的不断进步,传统的12V电气系统逐渐无法满足现代高性能电动汽车的需求,而48V电力系统的引入成为一种理想的解决方案。

weixin_43199439的博客 7807

YOLOv8 改进涨点 | 模块即插即用 直接可用

在目标检测任务中,注意力机制能够帮助模型聚焦于图像中的关键区域,显著提升检测精度。。创建模块代码注册模块修改任务解析tasks.py创建YAML配置文件模块核心优势适用场景计算开销SOCA捕获二阶统计信息,增强通道间相关性需要精细特征区分的场景中等SK自适应多尺度核选择多尺度目标检测中等偏高显式特征聚集-分配机制全局上下文建模中等A2-Net双线性注意力,高效全局交互复杂场景理解中等偏高CrissCross线性复杂度全局上下文高分辨率输入,长距离依赖较低。

u012133341的博客 2256

Spring Boot集成Redis实现缓存

前言 Spring Boot 集成 Redis 实现数据缓存,只需要添加一些注解,就无侵入地使用缓存了,无需额外的代码。 步骤 Spring Boot 集成 Redis 实现缓存主要分为以下三步: 1)加入 Redis 依赖; 2)加入 Redis 配置; 3)添加 Redis 缓存相关注解。 一、加入依赖 首先我们创建一个项目,并在项目中加入 Redis 依赖,项目依赖如下所示(由于使用 Redis 连接池,需额外引入 commons-pool2): <dependency.

panjican的博客 796

Vue3 - Element Plus 日期选择器 el-date-picker,设置 type=week 变成周选择器后,将选择周时修改为 “周一至周日“ 为一组范围(详细示例代码,新手小白秒会)

vue3,element-plus,DatePicker日期选择器,el-date-picker,周,type=week,周选择器,日期选择器week怎么拿到具体的时间范围,如何取week周选择器的value值,format如何设置,时间选择器按周选择时展示具体日期范围,vue3elementPlus日期选择器选择一周7天的数据格式怎么拿到,el-date-picker设置type等于week后怎么设置format属性,format和value-format怎么设置,范围选择器周,一周,选择一周7天时间

🏆 前端领域优质创作者 1万+

SpringCache缓存介绍

​ 前面提到了缓存有诸多的好处,于是大家就摩拳擦掌准备给自己的应用加上缓存的功能。但是网上一搜却发现缓存的框架太多了,各有各的优势,比如Redis[中央缓存-远程缓存]、Memcached、Guava、Caffeine[本地缓存]等等。​ 如果我们的程序想要使用缓存,就要与这些框架耦合。聪明的架构师已经在利用接口来降低耦合了,利用面向对象的抽象和多态的特性,做到业务代码与具体的框架分离。

几许的博客 1335

DeepFashion 服装识别:基于 YOLOv10 的深度学习实现与 UI 界面开发

随着深度学习的发展,目标检测算法在服装识别任务中表现出色,特别是 YOLO(You Only Look Once)系列模型。服装识别(Fashion Recognition)是计算机视觉领域的重要任务,广泛应用于。已提供,可用于服装分类、款式识别、虚拟试衣等应用。训练服装识别模型,并开发。

YOLO 802

计算机组成原理(第三版)唐朔飞-第五章输入输出系统-课后习题

计算机组成原理(第三版)唐朔飞-第五章输入输出系统-课后习题

weixin_45735391的博客 6万+

SpringCache、Redis实现指定过期时间

我们都知道springCache定义了缓存规范,其中redis的解决方案并不支持每个缓存key独自设置过期时间,本方案通过定义cacheName为特定格式,从而设置缓存过期时间。支持设置过期时间单位(默认秒)1、重写RedisCacheManager的createRedisCache方法。2、把TaRedisCacheManager交给spring管理。3、使用,为testCache设置过期时间为10小时。

优快云_Ty的博客 3113

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

设计模式—建造者模式及实例(BuilderPattern)

建造者模式(Builder Pattern)也称生成器模式,它属于创建型模式。

小嵩的博客 4002

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

建造者模式BuilderPattern

建造者模式BuilderPattern建造者模式简介应用场景:优点:缺点:典型例子:装配电脑。建造者模式结构:四大类产品类抽象建造者类具体建造者类指挥部类 建造者模式简介 一件产品/一个事物,由多个部件组成,这些部件可以自由替换,每个部件都有自己的创建过程,那么需要这个产品的客户端(使用者)可以忽略每个部件的创建过程,或者说使用者不关心你产品每个部件是如何产生的,你只要给我完整的产品就行,至于你各部件怎么建的、建好后又是如何装配成完整产品的,那是你的事,别特么让我知道,我嫌烦。 应用场景: (1) 需要生成

diezhongbing1358的博客 293

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

建造者模式(BuilderPattern)

原文参考出处:https://blog.youkuaiyun.com/u010102390/article/details/80179754 介绍: 建造者模式:指将一个复杂对象的构造与它的表示分离,使同样的构建过程可以创建不同的表示,这样的设计模式被称为建造者模式。它是将一个复杂的对象分解为多个简单的对象,然后一步一步构建而成。它将变与不变相分离,即产品的组成部分是不变的,但每一部分是可...

静风落叶的博客 221

设计模式之建造者模式(BuilderPattern)

一.意义 将一个复杂的对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。 说明:复杂对象的构建,比如一个对象有几十个成员属性,那么我们在创建这个对象,并给成员属性赋值时,就会很麻烦。采用建造者模式,就是把创建对象并给成员属性赋值的工作,分离出来,由建造者角色来完成,业务程序员直接调用导演类,获得复杂对象即可,无需再进行对象的创建工作了。 二.角色 建造者模式涉及到一下几种角色: Builder(抽象建造者):它为创建一个产品Product对象的各个部件指定抽象接口,在该接口中一般声明两类方

敲代码的小小酥的博客 415

设计模式——建造者模式(BuilderPattern)

建造者模式(Builder):将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。 UML图:

雪夜&流星的专栏 571

设计模式之建造者模式BuilderPattern(七)

建造者模式(Builder Pattern)使用多个简单的对象一步一步构建成一个复杂的对象。这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式。@Data:这是Lombok中提供的Getter和Setter方法和toString方法的注解。@AllArgsConstructor:这是Lombok中提供的包含所有参数的构造方法注解。@NoArgsConstructor:这是Lombok中提供的不包含任何参数的构造方法注解。3、OrderBuilder类。1、OrderItem类。

徐泗空的博客 1331

设计模式建造者模式(BuilderPattern)

核心模块:Builder抽象建造者、ConcreteBuilder具体建造者、Product产品角色、Director指挥者 所有代码请访问:git@code.aliyun.com:289804201/PatternLearn.git 使用场景:构建复杂对象,或者构件过程中需要强制的分布措施; 优点:客户可以精细的控制构建过程,将产品创建过程和产品本省分离,细节依赖于

didiao11300的专栏 290

您的设计模式——建造者模式【Builder Pattern】

又是一个周三,快要下班了,老大突然又拉住我,喜滋滋的告诉我“牛叉公司很满意我们做的模型, 又签订了一个合同,把奔驰、宝马的车辆模型都交给我我们公司制作了,不过这次又额外增加了一个新需 求:汽车的启动、停止、喇叭声音、引擎声音都有客户自己控制,他想什么顺序就什么顺序,这个没问题 吧?”。 看着老大殷切的目光,我还能说啥,肯定的点头, “没问题! ” ,加班加点做呗, “再苦再累就当自己二 百

454

设计模式——建造者模式

又叫生成器模式,是一种对象构建模式。它可以将复杂对象的建造过程抽象出来(抽象类别),使这个抽象过程的不同实现方法可以构造出不同表现(属性)的对象。2)、构造者模式,它允许用户只通过指定复杂对象的类型和内容就可以构建它们,用户不需要知道内部的具体构建细节。3)、构造者模式主要解决在软件系统中,当面临一个复杂对象的创建工作时,其通常由各个部分的子对象用一定的算法构成;由于需求的变化,这个复杂对象的各个部分经常面临剧烈的变化,但是将它们组合在一起的算法却相对稳定。

程序猿进阶 1773

生成器模式/建造者模式(BuilderPattern)

生成器模式/建造者模式(BuilderPattern):通过多个简单对象累积逐步构建成目标复杂的对象。这种设计模式属于创建型模式,提供创建对象的某种方式。 生成器模式/建造者模式的使用:在软件系统中有时候面临”某个极端复杂的对象"的创建需求,其通常由各个部分的子对象(部件对象)采用一定的算法构成;由于极端复杂需求的变化,这个极端复杂对象的各个部分经常面临着剧烈的变化,但是将各个部件组合在一起的逻辑算法却相对稳定。 基本的部件对象本身不会变但部件的组合经常变化时。 生成器(建造者)模式优点:建造者独立,易扩展

yanhaijunyan的博客 281

设计模式实现(四)建造者模式

1.什么是建造者模式(Builder Pattern) 建造者模式(Builder Pattern)又叫生成器模式,是一种对象创建型模式之一,用来隐藏复合对象的创建过程,它把复合对象的创建过程加以抽象,通过子类继承和重载的方式,动态地创建具有复合属性的对象,从而达到代码复用性。 建造者模式将复杂对象的构建与对象的表现分离开来,这样使得同样的构建过程可以创建出不同的表现。 2.建造者模式的优点 在用户不知道对象的建造过程和细节的情况下就可以直接创建复杂的对象。 用户只需要给出指定复杂对象的类型和内容; 建造

WormholeStack 1278

JAVA设计模式之建造者模式详解

建造者模式(builder pattern), 也被称为生成器模式, 是一种创建型设计模式.定义: 将一个复杂对象的构建与表示分离,使得同样的构建过程可以创建不同的表示。**建造者模式要解决的问题 **建造者模式可以将部件和其组装过程分开,一步一步创建一个复杂的对象。用户只需要指定复杂对象的类型就可以得到该对象,而无须知道其内部的具体构造细节。

励志成为一名优秀的全能型软件开发工程师。 4281
上一篇: nginx实现http服务配置
下一篇: Fork/Join框架
余生之君
博客等级 码龄10年 246粉丝 98原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值