设计原则

六大设计原则 本文主要阐述了设计模式的六大设计原则,掌握6大设计原则是应用23种设计模式的关键很多讲解设计模式的博主都忽视了设计原则的重要性,大部分讲解都是尽可能让你理解设计模式的基本原理,但在实际的项目开发中,你真的会使用吗?只有熟悉了基本的设计原则,才能设计出易于维护和扩展的软件架构。在学习设计原则之前,需得对抽象有一定的了解。不管是单个抽象,还是多重抽象,抽象始终是设计原则的核心。实际编程面对需求时,针对某一模块的功能处理,始终把抽象放在心里。C++抽象类。 阅读详情
SOLID
1. SRP
   A Single Responsibility Principle
   A class should have one, and only one, reason to change.

2. OCP
   A module should be open for extension but closed for modification.
   polymorphism is a way to implement it.

   Q: what's the difference between static polymorphism and dynamic polymorphism?

3. The Liskov Substitution Principle(LSP)
   Subclasses should be substitutable for their base classes.
  
   we should note the canonical Ellipse/Circle dilemma

4. The Dependency Inversion Principle(DIP)
   Depend upon Abstractions instead of concretions.

   we should note the difference between procedural architecture and OO architecture.

5. The Interface Segregation Principle(ISP)
   Many Client specific interfaces are better than one general purpose interface.
   so we can isolate the individule interface change. we can define interface according to the client category. Any change needed to be made on the existing interfaces, we can add a new interface instead of changing the existing interfaces. So we can avoid the issue of recompilation and redeployment.

6. Principles of Package Architecture
how to group together package

6.1 The Release Reuse Equivalency Principle(REP)
The granule of resue is the granule of release

6.2 The Common Closure Principle(CCP)
Classes that change together, belong together. So the package impact from release will be minimized.

6.3 The Common Reuse Principle(CRP)
Classes that aren't resued together should not be grouped together


6.4 The Acyclic Dependencies Principle(ADP)
The dependencies between packages must not form cycles.

Cycles can be broken in two ways:
1. create a new package
2. make use of the DIP and ISP
add a interface on the user side(who use the function) and the other side implement the interface.

6.5 The Stable Dependencies Principle(SDP)
Depend in the direction of stability.

I(Instability) = Ce/(Ca+Ce)
Ce: Efferent Coupling, outgoing dependencies
Ca: Afferent Coupling, incoming dependencies

So SDP can be rephrased as: Depend upon package whose I metric is lower than yours.

6.6 The Stable Abstractions Principle(SAP)
stable package should be abstract packages.

The stable package maybe hard to change, so it is not flexible; But we can make the stable package abstract, so it is easy to extend.

This is just a restatement of the DIP. That is , the package that the most depended upon should also be the most abstract.

A(Abstractness) = Na/Nc
Na: Number of abstract classes in the package
Nc: Number of classes in the package


7. KISS
Keep it simple and stupid.
Less is more.

8. CoC
Convention over Configuration, e.g. ROR

9. YAGNI
You Ain't Gonna need it. 极限编程中的一个概念,只实现目前需要的功能。
【The Art of Unit Testing 3_自学笔记05】第三章 单元测试核心技能之:用 stub 桩断开依赖项(Breaking dependencies with stubs) 本篇为《The Art of Unit Testing》全新第三版第三章自学笔记的上篇,主要涵盖了从概述到3.3小节的相关内容,介绍了单元测试中的 stub 桩以及 stub 与 mock 的重要区别,同时根据3.2小节的内容在本地进行了实测,并在笔记中记录了详细实战步骤。本文可作为系统学习软件单元测试的入门级参考资料,书中讲述内容反映了当前软件测试领域的主流观点及最新的代码最佳实践,同时基于 JavaScript 进行讲述,对前端开发人员十分友好。强烈建议收藏! 阅读详情

相关推荐

红外避障模块介绍

该传感器模块对环境光线适应能力强,其具有一对红外线发射与接收管,发射管发射出一定频率的红外线,当检测方向遇到障碍物(反射面)时,红外线反射回来被接收管接收,经过比较器电路处理之后,绿色指示灯会亮起,同时信号输出接回输出数字信号(一个低电平信号),可通过电位器旋钮调节检测距离,有效距离范围2~30cm,工作电压为3.3v-5v。该模块测距离2~~30cm,检测角度35°,检测距离可以通过电位器进行调节,顺时针调电位器,检测距离增加;1.VCC外接3.3v-5v电压(可以直接与5v单片机和3.3v单片机相连).

weixin_46251230的博客 2万+

面向对象:重用发布等价原则(REP)

     介绍一下Robert C. Martin提出的面向对象的设计原则中的重用发布等价原则。参考文档(http://www.objectmentor.com/resources/articles/granularity.pdf)     重用发布等价原则:Release Reuse Equivalency Principle (REP)。重用的粒度就是发布的粒度(The granu

步行者的专栏 7110

OpenCV 开闭运算

开运算和闭运算是将腐蚀和膨胀按照一定的次序进行处理。 但这两者并不是可逆的,即先开后闭并不能得到原来的图像。 开运算 开运算是先腐蚀后膨胀,其作用是:分离物体,消除小区域。特点:消除噪点,去除小的干扰块,而不影响原来的图像。 闭运算 闭运算与开运算相反,是先膨胀后腐蚀,作用是消除/“闭合”物体里面的孔洞,特点:可以填充闭合区域。 cv.morphologyEx(img, op, kernel) img: 要处理的图像 op: 处理方式:若进行开运算,则设为cv.MORPH_OPEN,若进行闭

꧁༺ʚvv༒catɞ༻꧂的博客 949

敏捷开发之原则 五大原则 SRP OCP LSP DIP ISP

一、面向对象设计原则内容来自《敏捷开发:原则、模式与实例》 SRP单一职责原则(Single Responsibility Principle): 就一个类而言,应该仅有一个引起它变化的原因。 OCP开放-封闭原则(Open Closure Principle): 软件实体(类,模块,函数等)应该可以扩展的,但不可修改。 LSPLiskov 替换原则(Liskov Substitution

心之所向 1万+

ROS2多线程处理RTSP视频流避坑指南:OpenCV解码丢帧问题解决方案

本文针对ROS2中处理RTSP视频流时OpenCV解码丢帧的常见问题,提供了专业的解决方案。通过深入分析单线程模型的瓶颈,提出并详细拆解了基于生产者-消费者多线程模型的健壮实现方案,有效分离数据采集与处理,从而显著提升视频流的稳定性和流畅度。

weixin_29199873的博客 168

生信人的一天~HIFI数据+HIC数据组装基因组

HIFI+HIC数据组装基因组!

qq_43337286的博客 9530

Package Design

Package Design Objectives Organize packages to reduce the impact of changes.Know alternative UML package structure notation. Introduction        If some package X is widely depended upon by the

CS 2103

波束管理 Beam Management

Beam Management in 5G NR   波束管理,是5G NR中基于信道质量来动态选择每个UE和gNB之间以什么方向和频率的波束beam来进行通信。   背景   5G NR(New Radio)支持非常高的数据速率和更低的延迟。5G NR支持FR1和FR2频段,FR1为亚6 GHz(450至6000 MHz);FR2为毫米波段(24.25 GHz至52.6 GHz)。   由于毫米波频带使用非常高的频率,因此会导致传播损耗和其他损耗。为了补偿损失,在这种频率下定向通信是必不可少的。

最忆是江南的博客 5826

面向对象设计原则、模式开篇

记得毕业后刚上班不久,一个同学打电话给我求救,说他正在做笔试题,要写几个常见的Design Pattern,然后问我什么是Design Pattern,叫我赶紧告诉他几个。身为菜鸟的我,要能回答如此问题还能叫菜鸟?因此要他自己搞定,结果可想而知,他面试杯具了。我也慢慢忘了这档事。然而不久后的一天,我面试时也被问到了这个Design Pattern,考官要我说下对于Design Pattern的

jjunjoe的专栏 811

Debezium系列之:使用指定值替代指定字段的值

Debezium系列之:使用指定值替代指定字段的值

zhengzaifeidelushang的博客 306

【漏洞复现】爱数云盘 Usrm_GetAllUsers 未授权访问漏洞

爱数 AnyShare存在未授权漏洞,未授权的攻击者可以通过该漏洞获取用户名信息。

qq_67810151的博客 3121

C++中的八大设计原则

C++ 中的八大设计原则可以帮助我们创建高内聚、低耦合的代码。

GOLOJO的博客 1909

【WRF-Chem工具】anthro_emiss 详解:生成人为排放数据

anthro_emiss 详解:生成人为排放数据

WW、forever的博客 2056

设计模式之六大设计原则

古人云: 有道无术,术可求.有术无道,止于术.而设计模式通常需要遵循一些设计原则,在设计原则的基础之上衍生出了各种各样的设计模式。设计原则是设计要求,设计模式是设计方案,使用设计模式的代码则是具体的实现。设计模式中主要有六大设计原则,简称为SOLID ,是由于各个原则的首字母简称合并的来(两个L算一个,solid 稳定的),六大设计原则分别如下:​1、单一职责原则(Single Responsibitity Principle)​2、开放封闭原则(Open Close Principle)​。

在青海看海的企鹅的博客 2923

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

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

RESTful API的设计原则和实现方式

/ 省略构造函数和 getter/setter 方法通过遵循这些设计原则和实现方式,可以设计出简洁、灵活、可扩展、易于理解和使用的 RESTful API,提供良好的用户体验和性能。

喔的嘛呀的博客 3437

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

设计原则有哪些?

设计原则是软件开发和系统设计中的核心指导思想,用于提高代码的可维护性、可扩展性、复用性和灵活性。:根据具体问题权衡原则(如性能 vs 可维护性),避免教条化。

qq_36929638的博客 1162

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

代码设计原则

代码设计原则是用于提高代码质量、易读性和可维护性的规则和准则。

猪猪 887

设计原则——SOLID

设计原则SOLID

qq_40843987的博客 5358

7种设计原则的详细讲解

一个类应该只有一个原因去改变,即一个类应该仅有一个职责。

软件开发工程师 1630

设计原则总结

面向对象设计原则概述 对于面向对象软件系统的设计而言,在支持可维护性的同时,提高系统的可复用性是一个至关重要的问题,如何同时提高一个软件系统的可维护性和可复用性是面向对象设计需要解决的核心问题之一。在面向对象设计中,可维护性的复用是以设计原则为基础的。每一个原则都蕴含一些面向对象设计的思想,可以从不同的角度提升一个软件结构的设计水平。 面向对象设计原则为支持可维护性复用而诞生,这些原则蕴含在很多设...

Jason_8848的博客 636

【RESTful】RESTful API的设计原则

设计一套高质量的RESTful API需要遵循一系列原则,以确保其可用性和可维护性。良好的API设计不仅能提升开发效率,还能改善用户体验。随着技术的不断进步,开发者应持续探索和优化这些设计原则,以适应不断变化的需求。本文旨在帮助读者深入理解RESTful API的设计原则,并提供实用的指导,以便在项目中有效应用这些原则。希望这些见解能为您的API设计提供帮助,助力您的开发工作更加顺利。

人生苦短,睡觉要紧,睡醒再说 3062

SOLID设计原则

设计原则--《架构整洁之道》读书笔记前言一、SRP:单一职责原则二、OCP:开闭原则三、LSP:里氏替换原则四、ISP:接口隔离原则五、DIP:依赖反转原则六、总结 前言          通常来说,要想构建一个好的软件系统,应该从写整洁的代码开始做起。毕竟,如果建筑所使用的砖头质量不佳,那么架构所能起到的作用也会很有限。反之亦然,如果建筑的架构设计不佳,那么其所用的砖头质量再好也没有用。这就是SOLID设计原则所要解决的问

woody218的博客 2190

HBase的 rowkey 设计原则

hbase所谓的三维有序存储的三维是指:rowkey(行主键),column key(columnFamily+qualifier),timestamp(时间戳)三部分组成的三维有序存储。 rowkey是行的主键,而且hbase只能用个rowkey,或者一个rowkey范围即scan来查找数据。所以 rowkey的设计是至关重要的,关系到你应用层的查询效率。 rowkey是以字典顺序排序的,存储的是字节码。 Rowkey设计原则 1.Rowkey的唯一原则 必须在设计上保证其唯一性。由于在HBas

zjjcchina的博客 3376

六大设计原则 (SOLID)

设计模式中主要有六大设计原则,简称为SOLID ,是由于各个原则的首字母简称合并的来(两个L算一个,solid 稳定的),六大设计原则分别如下

qq_45110186的博客 3078

OO设计原则

模式还是原则? 私以为,设计原则就像授之以渔,设计模式就像授之以鱼。 更侧重学习设计原则的原因 OO设计模式有很多,基础的设计模式为大名鼎鼎的GOF23设计模式,另外还有很多种特定领域的设计模式。套路太多。 设计模式是对设计原则实践的经验总结,可以让代码模块解耦,易于扩展和维护。随着微服务的推广,每一个功能模块都可以分离出一个独立的服务,并通过restFul接口调用进行功能模块间的解耦。微...

HELLOW,文浩 403
上一篇: 平移数组中部分连续元素
下一篇: PMBOK 学习笔记
firestone-sh
博客等级 码龄24年 19粉丝 431原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值