设计模式之Decorator——家装篇

微信小程序 - {“errMsg”:”requestPayment:fail banned”} 微信小程序调用wx.requestPayment支付失败返回错误(uniapp微信小程序微信支付报错) {“errMsg”:”requestPayment:fail banned”},微信小程序调用wx.requestPayment报错requestPayment:fail banned,uni-app微信小程序wx.requestPayment支付报错requestPayment:fail banned,拉起小程序支付报错,iPhone苹果ios真机微信支付报错,Android安卓手机微信支付报错,支付报错,商户配置,签名验证,uniapp 小程序支付微信支付一场,设置过b2b类目,确认了商户号相关功能正常 阅读详情

最近家里搞装修,做了一套家具,需要刷一下漆,因此我就去市场找了油漆师傅和油漆徒弟两个人。

油漆师傅主要买油漆和调油漆,油漆徒弟主要来刷油漆(团队精神?哈哈,不禁让让我想起CS,你先冲,我拣菜。)。

1、在这里,我们先把这个油漆工作定义成一个接口类:

public interface Work

{

  public void  brush();   //刷油漆

}

 

2、因为油漆师傅和油漆徒弟的任务是刷油漆,因此他们要对Work接口进行实现:

A:油漆徒弟

刷油漆的工作主要是由油漆徒弟来完成,所以我们把油漆徒弟定义成Brusher(油漆师傅在一旁说:“徒弟吗,就是要多干活。”,油漆徒弟小声嘀咕:“多你个头。”)。

public class Brusher implements Work{

  public void brush() {

    System.out.println("刷油漆");

  }

}

B:油漆师傅

我们把油漆师傅定义成Decorator。

public class Decorator implements Work{

  private Work work;

//油漆师傅的工作被放置在这个List中

  private ArrayList prework = new ArrayList();

//油漆师傅的默认工作

  public Decorator(Work work) {

    this.work = work;

    prework.add("买油漆");

    prework.add("调油漆");

  }

 

  public void brush() {//刷油漆, 油漆师傅也要实现此方法

    newWork();         //当油漆师傅接到活,就开始一个新的工作

  }

 

//新的工作

  public void newWork() {

    preWork();      //油漆师傅做的前期辅助工作

    work.brush();   //让徒弟干的刷油漆的工作

  }

 

//油漆师傅做的前期辅助工作

  public void preWork() {

    ListIterator listIterator = prework.listIterator();

    while (listIterator.hasNext()) {

      System.out.println( ( (String) (listIterator.next())) + "完成");

    }

  }

3、编写测试类:

public class test {

  public static void  main(String args[]) {

    Work bursher = new Brusher();

    Work decorator = new Decorator(bursher); 

    decorator.brush();

   //我把活交给油漆师傅,油漆师傅下来再把实际刷油漆的工作指派给油漆徒弟干

  }

 

4、说明:

A:代码只用来学习Decorator模式,要运行的话,必须要做一点改动。

B:在这过程中,我只和油漆师傅打交道,具体的刷油漆那是由油漆师傅和油漆徒弟之间的事,我是不用关心的。

C:使用Decorator的理由是:这些功能需要由用户动态决定加入的方式和时机.Decorator提供了"即插即用"的方法,在运行期间决定何时增加何种功能.

Virtual Hard Disk version 2 (VHDX) 文件格式详解 VHDX 镜像格式详解 0. References windows github 1. Overview Microsoft 虚拟化产品中常用的映像格式是虚拟硬盘版本 2 (VHDX) 映像格式。该规范基于可用文档,并通过分析测试数据进行了增强。 VHDX 镜像格式种类 固定硬盘镜像 动态硬盘镜像 差异硬盘镜像 VHDX 镜像文件由以下元素构成: file (type) identifier 2x image headers 2x region tables log or metadata journ 阅读详情

相关推荐

PX4(CUAV v6x 飞控)+ QAV250 机架无人机组装测试教学(无人机电机转向不对,如何反转电机?)

本文介绍无人机的组装与飞控调试:1.无人机的硬件组装。2.无人机飞控软件的下载,电机、遥控器、电调的校准与调试。

weixin_74185504的博客 2889

设计模式之Memento——系统篇(原创)

设计模式之Memento——系统篇  经常使用计算机的人恐怕对系统备份(Memento)不会陌生,当你的Windows系统运行正常时,对它进行备份,当系统运行有问题时,就可以调用备份快速的将系统恢复,这样就可以大量节省重新装系统的痛苦,特别是当你缺少某一驱动,或在装系统是出现一些怪问题时,犹为痛苦。我想有过这种经历的人应该很了解吧,呵呵!好了,下面让我们看看这个过程该如何实现吧:

lxgljj的专栏 4151

超详细版risc-v五级流水线cpu硬件设计实现解析

深入剖析risc-v五级流水线cpu的硬件架构与设计细节,涵盖指令流程、模块划分与关键时序控制,帮助理解risc-v五级流水线cpu的工作机制与优化策略。

weixin_42437253的博客 1630

设计模式之Decorator——家装篇(原创)

设计模式之Decorator——家装篇 最近家里搞装修,做了一套家具,需要刷一下漆,因此我就去市场找了油漆师傅和油漆徒弟两个人。油漆师傅主要买油漆和调油漆,油漆徒弟主要来刷油漆(团队精神?哈哈,不禁让让我想起CS,你先冲,我拣菜。)。1、在这里,我们先把这个油漆工作定义成一个接口类:public interface Work{  public void  brush()

lxgljj的专栏 2683

别再只跑recon-all了!FreeSurfer实战:从T1图像到freeview可视化的完整避坑指南

本文详细解析FreeSurfer从T1图像处理到freeview可视化的全流程,包括环境配置、recon-all深度解析、高级可视化技巧及性能优化策略。特别针对常见错误提供解决方案,帮助用户高效完成MRI数据分析,避免常见陷阱。

weixin_33404102的博客 353

COMSOL仿真避坑指南:列管反应器模拟中多孔介质与化学反应设置的5个常见错误

本文详细解析了COMSOL仿真中列管反应器模拟的5个常见错误,包括多孔介质模型选择、化学反应接口配置、对流扩散方程处理、薄层热阻设置及网格独立性验证。特别针对多孔介质与化学反应设置的误区,提供了实用的判断标准和修正方法,帮助工程师避免计算偏差,提升仿真精度。

weixin_29597551的博客 321

设计模式之Decorator(家装篇)

最近家里搞装修,做了一套家具,需要刷一下漆,因此我就去市场找了油漆师傅和油漆徒弟两个人。           油漆师傅主要买油漆和调油漆,油漆徒弟主要来 刷油漆(团队精神?哈哈,不禁让让我想起 CS ,你先冲,我拣菜。)。          1 、在这里,我们先把这个油漆工作定义成一个接口类:           public interface Work           {         

Net 404

OPCUA二(通过OPCUA服务器访问CPU)

摘要:本文介绍了使用UaExpert软件连接西门子PLC的OPC UA配置方法,包括IP地址设置(默认端口4840)、安全认证和证书信任流程。详细说明了数据访问操作,如变量拖拽监控和属性解读(NodeId、Value、状态码等)。特别强调连接仿真Advance7时需先启动实例。最后预告下章将讲解通过KerServer访问CPU。文章涵盖配置步骤、常见问题处理及实用技巧,适合工业自动化开发者参考。

欢迎来到RaymondLeigh的知识共享基地 1337

Decorator设计模式

Decorator 动机(Motivation) 在某些情况下我们可能会“过度地使用继承来扩展对象的功能”,由于继承为类型引入的静态特质,使得这种扩展方式缺乏灵活性; 并且随着子类的增多(扩展功能的增多),各种子类的组合(扩展功能的组合)会导致更多子类的膨胀。 如何使“对象功能的扩展”能够根据需要来动态地实现?同时避免“扩展功能的增多”带来的子类膨胀问题?从而使得任何“功能扩展变化”所导致的影响...

量子象限 388

从零实现机械臂抓取仿真:用MoveIt+Gazebo完成物体pick&place全流程

本文详细介绍了如何使用ROS的MoveIt框架与Gazebo仿真环境,从零构建机械臂抓取仿真系统。涵盖环境搭建、MoveIt配置、Gazebo集成、抓取动作实现等全流程,帮助开发者掌握机械臂控制的核心技术,实现高效的pick&place任务。

weixin_29250403的博客 476

基于STM32设计的电能质量控制系统_353

本项目基于STM32F103RCT6微控制器设计了一套电能质量控制系统,实现了对火焰、烟雾、环境温湿度、电压、电流及功率等多项参数的实时监测与报警。系统通过MQ2烟雾传感器、火焰传感器、SHT30温湿度传感器及电力参数采集模块采集数据,采用高电平触发有源蜂鸣器进行异常报警。采集的数据通过ESP8266无线模块以AP+TCP模式上传至基于Qt开发的手机APP和电脑上位机,实现远程实时监控和历史数据管理。系统配备1.44寸LCD显示屏,实现本地数据显示。软件采用Keil5开发,采用寄存器编程方式,提高系统响应速

253

Hyperf 極簡 DB 元件實戰指南:輕量 PDO 封裝、連線池與多庫配置全解析

本指南以 Hyperf 官方元件 `hyperf/db` 為核心,深入講解這套「極簡資料庫存取層」的安裝、配置、API 使用與底層運作原理。有別於功能完整但較為厚重的 `hyperf/database`,`hyperf/db` 直接封裝 PDO 與連線池,特別適合追求極致效能、只需要原生 SQL 的微服務與中介層場景。讀完本文,你將掌握 `hyperf/db` 的全部配置參數、五種核心方法、多庫切

gitblog_00731的博客 619

FT2004(D2000)开发实战之网口stmmac报错调试(Failed to reset the dma)

网口stmmac报错调试(Failed to reset the dma)

嵌入式Linux 3584

设计模式(JAVA)——Decorator模式

设计模式(java)之decorator

读书 好学 求知 288

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 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")

设计模式学习(十二):Decorator装饰器模式

假如现在有一块蛋糕,如果只涂上奶油,其他什么都不加,就是奶油蛋糕。如果加上草莓,就是草莓奶油蛋糕。如果再加上一块黑色巧克力板,上面用白色巧克力写上姓名,然后插上代表年龄的蜡烛,就变成了一块生日蛋糕。不论是蛋糕、奶油蛋糕、草莓蛋糕还是生日蛋糕,它们的核心都是蛋糕。不过,经过涂上奶油,加上草莓等装饰后,蛋糕的味道变得更加甜美了,目的也变得更加明确了。程序中的对象与蛋糕十分相似。首先有一个相当于蛋糕的对象,然后像不断地装饰蛋糕一样地不断地对其增加功能,它就变成了使用目的更加明确的对象。

m0_49499183的博客 2492

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

[DP]Decorator设计模式

Decorator设计模式,装饰器设计模式,io流中的装饰器模式,spring中的装饰器模式

HeapStackk的博客 525

设计模式(结构型——Decorator模式)

设计模式八、Decorator模式8.1 Decorator模式的概念8.2 Decorator模式的实现 八、Decorator模式 8.1 Decorator模式的概念 使用场景 与Bridge模式的应用场景有些许类似。都是由于类需要在不同维度上进行拓展,如果单单通过继承的方式,每种组合的关系都定义出一个类,耦合程度非常高,且类的数量也会非常庞大。 不同之处 Bridge模式应对的是多维度且固定的拓展,例如,坦克游戏中的坦克模型有型号之分,且每种型号的坦克在不同的平台上都有对应的实现;一辆坦克,必

qq_37112587的博客 355

【设计模式】Decorator模式

目录 动机(Motivation) 模式定义 实例 Decorator模式的结构 要点总结 动机(Motivation) *在某些情况下我们可能会“过度使用继承来扩展对象的功能”,由于继承为类型引入的静态特质,使这种扩展方式缺乏灵活性;并且随着子类的过度增多(扩展功能的增多),各种子类的组合(扩展功能的组合)会导致更多的子类膨胀。 *如何使“对象功能的扩展“能够根据需要动态地...

qq_28011221的博客 261

【C++设计模式之Decorator装饰模式】

Decorator装饰模式是一种动态扩展对象功能的设计模式,通过组合而非继承来增加对象的职责,避免了继承带来的类膨胀问题。该模式的核心思想包括动态扩展、透明性和组合优于继承。

weixin_43488529的博客 1187

图解设计模式 (十二)Decorator 模式

读书笔记 仅供参考 简述 Decorator 模式(装饰着模式)是维持装饰边框和装饰物的一致性,为对象增加新的功能,但是它还是原来的对象 UML 和角色 Component 增加功能的核心角色,就像是一块蛋糕(抽象),可以被添加很多奶油和水果。Component 定义了蛋糕的接口(API)。 ConcreteComponent 实现了 Component 角色定义的接口(API)的具体蛋糕。 Decorator 具有与 Component 角色相同的接口(API),在内部保存了被装饰对象—

zhangmiaoping23的专栏 707

Java设计模式之Builder和Decorator

Java设计模式                                        之                            Builder和Decorator 1、建造者模式(Builder) 工厂类模式提供的是创建单个类的模式,而建造者模式则是将各种产品集中起来进行管理,用来创建复合对象,所谓复合对象就是指某个类具有不同的属性,其实建造者模式就是前面抽象工

848

设计模式:装饰模式(Decorator)

设计模式:装饰模式(Decorator)

ProgramNovice的博客 1782
上一篇: 设计模式之Facade——家庭篇
下一篇: 设计模式之Visitor——送礼篇
cyokin
博客等级 码龄24年 0粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值