SOLID原则学习,接口隔离原则(Interface Segregation Principle, ISP)

SOLID - 接口隔离原则(Interface Segregation Principle) 接口隔离原则是创建高效、维护良好的面向对象系统的重要原则之一。在云原生编程中,遵循这一原则可以设计出更加灵活、可扩展的微服务系统。通过识别不同客户端的需求,创建小而专用的接口,并将服务模块化,能够显著提高系统的可维护性和灵活性。接口隔离原则不仅适用于传统的面向对象编程,同样也适用于现代的云原生架构设计,是确保系统稳定性、可扩展性及高效性的重要设计指南。 阅读详情

在这里插入图片描述


1. 定义

接口隔离原则(Interface Segregation Principle, ISP)
接口隔离原则是面向对象设计中的五大原则(SOLID)之一,由Robert C. Martin提出。其核心思想是:

客户端不应该依赖它们不需要的接口。

换句话说,一个类不应该被迫实现它不需要的方法。接口应该尽量细化,每个接口只负责一个特定的功能,而不是将所有功能都集中在一个庞大的接口中。


2. 为什么要遵循接口隔离原则?

1. 减少耦合:细化的接口可以减少类之间的依赖,降低耦合度。

2. 提高可维护性:当接口职责单一,修改一个接口不会影响到其他不相关的类。

3. 增强可读性:细化的接口更容易理解和维护。


3. 违反接口隔离原则的例子

假设我们有一个IMachine接口,定义了打印机、扫描仪和传真机的功能:

class IMachine {
public:
    virtual void print(const std::string& document) = 0;
    virtual void scan(const std::string& document) = 0;
    virtual void fax(const std::string& document) = 0;
};

然后我们有一个Printer类,它只需要实现打印功能:

class Printer : public IMachine {
public:
    void print(const std::string& document) override {
        // 实现打印功能
    }

    void scan(const std::string& document) override {
        // 打印机不需要扫描功能,但被迫实现
        throw std::runtime_error("Not implemented");
    }

    void fax(const std::string& document) override {
        // 打印机不需要传真功能,但被迫实现
        throw std::runtime_error("Not implemented");
    }
};

在这个例子中,Printer类被迫实现了scan和fax方法,尽管它并不需要这些功能。这违反了接口隔离原则。


4. 遵循接口隔离原则的改进

我们可以将IMachine接口拆分为多个更小的接口,每个接口只负责一个功能:

class IPrinter {
public:
    virtual void print(const std::string& document) = 0;
};

class IScanner {
public:
    virtual void scan(const std::string& document) = 0;
};

class IFax {
public:
    virtual void fax(const std::string& document) = 0;
};

然后,Printer类只需要实现IPrinter接口:

class Printer : public IPrinter {
public:
    void print(const std::string& document) override {
        // 实现打印功能
    }
};

如果有一个多功能设备,比如MultiFunctionMachine,它可以同时实现多个接口:

class MultiFunctionMachine : public IPrinter, public IScanner, public IFax {
public:
    void print(const std::string& document) override {
        // 实现打印功能
    }

    void scan(const std::string& document) override {
        // 实现扫描功能
    }

    void fax(const std::string& document) override {
        // 实现传真功能
    }
};

5. 总结

通过将庞大的接口拆分为多个小接口,我们可以确保每个类只实现它所需要的功能,避免了不必要的依赖和复杂性。这不仅提高了代码的可维护性,还使得系统更加灵活和可扩展。

关键点
1. 接口职责单一:每个接口只负责一个功能。

2. 避免强迫实现不需要的方法:类不应该被迫实现它不需要的方法。

3. 提高灵活性:细化的接口使得系统更容易扩展和修改。

遵循接口隔离原则可以帮助我们设计出更加清晰、灵活和可维护的系统。

PHP面向对象设计:SOLID五大原则实战指南 SOLID是面向对象编程中保障系统可维护性的核心设计原则集合,涵盖单一职责、开闭原则、里氏替换、接口隔离与依赖倒置。其本质并非语法规范,而是对‘变化轴’的识别与封装——通过抽象接口隔离易变逻辑,使业务代码免受框架、存储、通知等技术细节侵扰。在PHP这类动态弱类型语言中,SOLID能显著降低重构成本、提升单元测试覆盖率、支撑多技术栈平滑演进。本文结合Laravel/ThinkPHP等主流框架实践,详解如何用接口契约拆分职责、用策略模式实现热插拔扩展、用依赖注入解耦基础设施,并给出遗留系统渐进式重构路径。 阅读详情

相关推荐

C#实战:如何用winmm.dll打造毫秒级高精度定时器(附完整代码)

本文详细介绍了在C#中利用winmm.dll实现毫秒级高精度定时器的完整方案。针对.NET内置定时器精度不足的问题,通过调用timeSetEvent等原生API,提供了超越系统时钟中断周期的精准定时能力。文章包含核心原理剖析、完整的封装类代码以及音视频处理、游戏开发等场景下的实战应用与性能调优指南。

ujm5678901的博客 697

北风设计模式课程---接口分离原则(Interface Segregation Principle)

北风设计模式课程---接口分离原则(Interface Segregation Principle) 一、总结 一句话总结: 接口分离原则描述为 "客户类不应被强迫依赖那些它们不需要的接口"。 接口不是为特定的客户类服务,而服务了多个不同的客户类。 1、接口分离原则(Interface Segregation Principle)用来解决什么问题? 用于处理胖接口(fa...

weixin_30616969的博客 213

python k线顶分型_【缠论】分型、笔的定义及其程序化

K线包含关系处理和分型的定义如果一个K线的高低点全在另一K线的范围里,称之为包含关系。针对这种K线,需要进行一些处理,去除包含关系,处理方法:向上时,把两K线的高点当高点,而两K线低点中的较高者当成低点;反之,当向下时,把两K线的低点当低点,而两K线高点中的较低者当成高点,这样就把两K线合并成一新的K线。经过这样的处理,所有K线图都可以处理成没有包含关系的图形。两K线的包含关系,可以分成四种:1)...

weixin_39717152的博客 2830

接口隔离原则(Interface Segregation Principle, ISP)

在软件设计、编码过程中有几个基本原则即SOLID原则,学习理解能够帮忙我们写出更健壮的代码。SOLID是五个基本原则的首字母。这五个原则如下: Single responsibility Open–closed Liskov substitution Interface segregation Dependency inversion 此篇来学习一下接口隔离原则(Interface Segregation Principle) 接口隔离原则: Clients should not.

一斗水的专栏 354

DC-DC电源PCB布局实战:从EMI优化到热管理

本文深入探讨了DC-DC电源PCB布局的核心实战技巧。文章从分析电流环路入手,强调通过优化“黄金三角”布局以最小化环路面积,从而有效抑制EMI并提升效率。详细阐述了功率器件摆放、地线分割、敏感信号布线、电感下方铺铜策略以及热管理设计等关键步骤,为工程师提供了一套从理论到实践的完整布局指南。

z5a6b的博客 724

Python反爬实战|动态渲染+高可用IP代理集群,稳定爬取京东/淘宝10万+商品数据

做Python电商爬虫的同学,应该都对京东、淘宝的反爬机制深有体会——这两个平台的反爬体系,堪称国内网站的天花板,远比普通资讯、政务网站的反爬严格十倍不止。用requests库请求商品列表,返回的永远是只有骨架的空HTML,商品标题、价格、销量全是前端JS异步加载,抓包分析接口发现参数全是加密的signtoken,解密成本无限高;用selenium开无头浏览器爬取,刚爬3-5页就触发风控,页面直接返回403,IP被封禁,甚至连Cookie都直接失效;

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1589

【SOLID原则前端中的应用】接口隔离原则(Interface Segregation Principle,ISP)- vue3示例

按照接口隔离原则,将这个需求分解成两个独立的组件:一个负责展示用户信息(UserDisplay.vue),另一个负责编辑用户信息(UserEdit.vue)。换句话说,我们应该避免创建包含过多职责的“胖接口”,而应该创建细粒度的接口,使得每个接口只包含客户端实际需要的方法。这样做不仅使组件更加简洁、易于理解和测试,还可以在需要时更容易地对组件进行重用和维护。通过这种方式,确保每个组件都有明确的职责,避免创建包含过多职责的“胖组件”。在Vue 3中,这可以通过将组件的职责分解成更小的、功能单一的组件来实现。

无言非影的博客 676

解决Gradle中NPM命令失效问题

摘要:本文分析了IntelliJ IDEA中Gradle执行npm命令失败的问题,报错显示"npm"文件不存在。通过确认npm安装路径、检查系统PATH与Gradle环境的差异,提出两种解决方案:1) 在build.gradle中使用npm绝对路径;2) 通过launchctl修改用户PATH。实例展示了如何修改Gradle脚本或系统配置来解决该问题,指出跨平台开发中环境变量配置的重要性。文章为开发者提供了处理类似问题的实用方法。

2501_90323865的博客 91

接口隔离原则(Interface Segregation Principle, ISP)是面向对象设计五大原则(SOLID)之一

常见应对策略包括: - **接口细化**:按功能角色(如 `Readable`, `Writable`, `Searchable`)拆分; - **使用适配器模式(Adapter)**:为遗留胖接口提供轻量包装,仅暴露所需方法; - **引入门面模式(Facade)**:为复杂子系统提供统一、精简的高层接口,间接实现接口隔离; - **组合优于继承**:通过组合多个细粒度接口来构建能力,而非继承一个大接口。

[Blog][Domain] programb.blog.csdn.net 284

高效批量转换Java接口为MCP服务:降低重复劳动的实战指南

高效批量转换Java接口为MCP服务:降低重复劳动的实战指南

专注于编程、AI、人工智能等多个领域内容研究和分析 731

LDRA Testbed(TBrun)软件单元测试_实例讲解(对多次调用的函数打桩)

在之前的文章《LDRA Testbed(TBrun)软件单元测试_操作指南》中,已经讲解了如何使用TBrun进行软件单元测试的基本操作步骤。本篇文章将结合实例进一步讲解被测函数中包含多次调用其他函数时,如何对其打桩来实现测试目的(详细的操作流程本文不再重述,若有不清楚的,可以结合之前的操作指南一起来看)。本文以一个被测函数作为示例,讲解了如何使用Testbed(TBrun)对涉及到多次调用其他函数的被测函数进行单元测试。本文的示例可能比较简单,但是思路、方法和流程都是通用的,希望对大家有所帮助。

文章主要涉及嵌入式软件开发、测试、项目管理等,欢迎交流,共同进步。 1470

接口隔离原则(Interface Segregation Principle)

接口隔离原则是由罗伯特·C·马丁(Robert C. Martin)在他的著作《敏捷软件开发:原则、模式与实践》(Agile Software Development: Principles, Patterns, and Practices)中首次提出的。该原则是SOLID设计原则中的一部分,旨在解决接口设计过于庞大、不够灵活的问题。

wang2leee的博客 427

基于毫米波生物感知雷达+STM32设计的独居老人居家监护系统(微信小程序)(192)

当前基于STM32设计的独居老人居家监护系统为独居老人提供一种简便、实时的健康监护服务。该系统通过集成多种传感器和功能模块,能够实时监测老人的生理指标、姿态以及室内环境状况,并通过微信小程序远程显示数据,当出现异常情况时及时发出报警提醒。

1万+

IPTV_Player_2.0源码架构解析:Python、Go、Rust与C如何在一个播放器里协作

IPTV_Player_2.0 是一款支持 M3U 播放列表、EPG 电子节目指南与社区频道列表的开源 IPTV 播放器,覆盖 Windows、macOS、Linux 与 TV Box。它的源码目录里同时出现 Python、Go、Rust 和 C 四种语言,本文带你逐层看懂这套多语言播放器架构的设计思路,无需任何语言基础也能 5 分钟读完。 ## 仓库目录结构:一眼看懂多语言布局 打开仓库,每

gitblog_01038的博客 371

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

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

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

接口隔离原则有哪三种应用?

接口隔离原则的英文翻译是“ Interface Segregation Principle”,缩写为 ISP。Robert Martin 在 SOLID 原则中是这样定义它的:“Clients should not be forced to depend upon interfaces that they do not use。”直译成中文的话就是:客户端不应该被强迫依赖它不需要的接口。其中的“客户端”,可以理解为接口的调用者或者使用者。 实际上,“接口”这个名词可以用在很多场合中。生活中我们可以用它来指插

鸭梨的博客 267

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

接口隔离原则 (Interface Segregation Principle)

该原则指导我们在设计接口时,应该将庞大的接口拆分为多个小接口,使得类只依赖于它们需要的接口,而不依赖于它们不需要的接口。接口隔离原则在接口设计中具有重要价值,通过拆分庞大的接口为多个小接口,使得类只依赖于它们需要的接口,避免了类依赖不必要的功能。在本文中,我们将深入了解接口隔离原则的原理,详细介绍它在软件设计中的价值,并通过示例代码来解析如何正确应用该设计原则。总结起来,接口隔离原则是面向对象设计中的重要原则,通过拆分庞大接口为多个小接口,使得类只依赖于它们需要的接口,避免了类依赖不必要的功能。

Jake_cai的博客 384

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

SOLID 原则

其实,外国人喜欢把一些重要且普遍或大力宣传让特定群体知道的东西弄成某几个单词或句子的首字母组成一个新的“词”,而这个词一般人是无法从字面上去理解,也不可能,因为它是纯粹的字母,根本没有什么特殊的意思,必须额外的脑补很多这些知识,你必须去找出它们原来是哪些单词才有可能知道它的意思。这也是汉语的神奇之处,哪怕是新词,也能通过组词把它的意思呈现出来。所以SOLID也是这样来的,SOLID如果不在软件行业里的话,真的很难知道什么是SOLID principle,它其实是软件设计的五大原则: 原则1:Single

weixin_40763897的博客 1013

NestJS 接口隔离原则(ISP)实战指南:以 rsschool-app 依赖注入实践拆分“胖接口“

本文围绕 [rsschool-app](https://link.gitcode.com/i/77fb74b943d5ede7f25c8aeac4afc524) 仓库中 `.agents/skills/nestjs-best-practices` 技能库的 `di-interface-segregation` 规则展开,系统讲解在 NestJS 后端中如何落实 SOLID 中的接口隔离原则(Int

gitblog_00226的博客 450

面向对象设计原则:SOLID原则详解

SOLID原则是面向对象编程中的五大核心设计原则,包括单一职责、开闭原则、里氏替换、接口隔离和依赖倒置。这些原则通过Python代码示例展示了违反和遵循时的区别:单一职责原则要求每个类只承担一个职责;开闭原则提倡通过扩展而非修改来增加功能;里氏替换原则确保子类能完全替代父类。遵循SOLID原则可使代码更健壮、易维护和可扩展。

fykam的博客 1293

设计模式 - 五大设计原则 - 接口隔离原则 (Interface Segregation Principle, ISP)

迪米特法则

HongSH945的博客 274

Interface Segregation Principle 接口隔离原则

Interface Segregation Principle 接口隔离原则 Introduction 介绍 The Interface Segregation principle states that no implementation of an interface should be forced to depend on methods it does not use. Have...

草样涂荼 666

Interface Segregation Principle (ISP) - OO设计的接口分隔原则

Clients should not be forced to depend upon interfaces that they do not use. 前言Robert C. Martin氏为我们总结了在面向对象的设计(OOD)中应该遵循的原则,这些原则被称为“Principles of OOD”,关于“Principles of OOD”的相关文章可以从Object Menter得到。

why_rj的专栏 630

面向对象设计的五个核心原则——SOLID

原则在快餐店点餐系统中的体现SRP菜单、计算价格、支付、打单分成不同类OCP新增折扣(节日/学生)不修改价格计算代码LSP所有支付方式(现金/信用卡)行为一致,不抛出额外限制ISP堂食不需要短信接口,外卖才需要,接口分开DIP点餐控制器依赖接口,而不是具体的微信支付这样设计出来的系统,后续加新菜品、新支付方式、新折扣活动,都只需新增类,而不是在旧代码里改来改去,也更容易写单元测试。

学习记录 667

Awesome-software-craftsmanship中的SOLID原则:编写高质量代码的终极指南

欢迎来到软件工艺的世界!🎯 在awesome-software-craftsmanship项目中,我们探索如何通过SOLID原则提升代码质量,让您的软件工程技能达到专业水准。SOLID原则是软件工艺的基石,这些面向对象设计原则能帮助开发者创建可维护、可扩展且健壮的代码系统。无论您是编程新手还是经验丰富的开发者,掌握这五个核心原则都将彻底改变您的编码方式。 ## 🔍 什么是SOLID原则?

gitblog_00051的博客 446

SOLID软件设计原则

SOLID(6)。Single Responsibility Principle,Liskov Substitution Principle,Dependence Inversion Principle,Interface Segregation Principle, Least Knowledge Principle(Law of Demeter ),Open Close Principl...

作一个独立连续的思考者 360

C++,std::queue 详解

std::queue 是 C++ 标准模板库(STL)中的一个容器适配器,它提供了一种先进先出(FIFO)的数据结构。std::queue 通常被用于存储元素集合,并且只允许在尾部添加新元素(push),在头部移除元素(pop)。这种特性使得 std::queue 成为实现队列行为的理想选择。

汽车电子软件领域知识分享 4130
上一篇: SOLID原则学习,里氏替换原则(Liskov Substitution Principle, LSP)
下一篇: SOLID原则学习,依赖倒置原则(Dependency Inversion Principle, DIP)
智驾
博客等级 码龄11年 6679粉丝 574原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智驾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址