PHP的SOLID设计原则
SOLID Design Principles,
这是一个比设计模式更高级别的概念,
以构建良好代码为目标,真正掌握了就是大师级别了。
我~~~仅知晓~
/*SOLID Design Principles • S: Single responsibility principle (SRP) • O: Open/closed principle (OCP) • L: Liskov substitution principle (LSP) • I: Interface Segregation Principle (ISP) • D: Dependency inversion principle (DIP) The single responsibility principle deals with classes that try to do too much. The responsibility in this context refers to reason to change. As per the Robert C. Martin definition: "A class should have only one reason to change." The open/closed principle states that a class should be open for extension but closed for modification, as per the definition found on Wikipedia: "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" The open for extension part means that we should design our classes so that new functionality can be added if needed. The closed for modification part means that this new functionality should fit in without modifying the original class. The class should only be modified in case of a bug fix, not for adding new functionality. The Liskov substitution principle talks about inheritance. It specifies how we should design our classes so that client dependencies can be replaced by subclasses without the client seeing the difference, as per the definition found on Wikipedia: "objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program" While there might be some specific functionality added to the subclass, it has to conform to the same behavior as its base class. Otherwise the Liskov principle is violated. When it comes to PHP and sub-classing, we have to look beyond simple concrete classes and differentiate: concrete class, abstract class, and interface. Each of the three can be put in the context of a base class, while everything extending or implementing it can be looked at as a derived class. The Interface Segregation Principle states that clients should only implement interfaces they actually use. They should not be forced to implement interfaces they do not use. As per the definition found on Wikipedia: "many client-specific interfaces are better than one general-purpose interface" What this means is that we should split large and fat interfaces into several small and lighter ones, segregating it so that smaller interfaces are based on groups of methods, each serving one specific functionality. The dependency inversion principle states that entities should depend on abstractions and not on concretions. That is, a high level module should not depend on a low level module, rather the abstraction. As per the definition found on Wikipedia: "One should depend upon abstractions. Do not depend upon concretions." This principle is important as it plays a major role in decoupling our software. */
PHP的SOLID设计原则的更多相关文章
- SOLID 设计原则 In C# 代码实现
[S] Single Responsibility Principle (单一职责原则) 认为一个对象应该仅只有一个单一的职责 namespace SingleResponsibilityPrinci ...
- 适用于Java开发人员的SOLID设计原则简介
看看这篇针对Java开发人员的SOLID设计原则简介.抽丝剥茧,细说架构那些事——[优锐课] 当你刚接触软件工程时,这些原理和设计模式不容易理解或习惯.我们都遇到了问题,很难理解SOLID + DP的 ...
- SOLID设计原则
SOLID设计原则 Single Responsibility Principle单一职责原则 单一职责原则(SRP)表明一个类有且只有一个职责. 一个类就像容器一样,它能添加任意数量的属性.方法等. ...
- 工作那么久,才知道的 SOLID 设计原则
认识 SOLID 原则 无论是软件系统设计,还是代码实现,遵循有效和明确的设计原则,都利于系统软件灵活可靠,安全快速的落地,更重要的是能灵活地应对需求,简化系统扩展和维护,避免无效的加班.本文主要讨论 ...
- SOLID 设计原则
SOLID 原则基本概念: 程序设计领域, SOLID (单一功能.开闭原则.里氏替换.接口隔离以及依赖反转)是由罗伯特·C·马丁在21世纪早期 引入的记忆术首字母缩略字,指代了面向对象编程和面向对象 ...
- 面向对象SOLID设计原则之Open-Closed原则
首先,我们看下开放-封闭原则(Open-Closed Principle,简称OCP)的概念: 是指软件实体(类.模块.函数等)应该可以扩展,但是不可修改. 任何新功能(functionality)应 ...
- SOLID架构设计原则
最近通读了<架构整洁之道>,受益匪浅,遂摘选出设计原则部分,与大家分享,希望大家能从中获益. 以下为书中第3部分 设计原则的原文. 设计原则概述 通常来说,要想构建-个好的软件系统,应该从 ...
- 经典设计原则 - SOLID
SOLID 设计原则包含以下 5 种原则: 单一职责原则(Single Responsibility Principle, SRP) 开闭原则(Open Closed Principle, OCP) ...
- Java程序员应该了解的10个面向对象设计原则
面向对象设计原则: 是OOPS(Object-Oriented Programming System,面向对象的程序设计系统)编程的核心,但大多数Java程序员追逐像Singleton.Decorat ...
随机推荐
- du和ls的区别:如何正确计算文件大小
上一篇文章写到的权限检查脚本,后来我又加入了 apk size 对比的功能,分享给组内同事使用后,暴露出一个问题:脚本输出的 apk size 和 Jenkins 出包信息以及电脑上显示的存储大小都有 ...
- Vue组件的操作-自定义组件,动态组件,递归组件
作者 | Jeskson 来源 | 达达前端小酒馆 v-model双向绑定 创建双向数据绑定,v-model指令用来在input,select,checkbox,radio等表单控件.v-model指 ...
- 33,Leetcode 搜索旋转排序数组-C++ 递归二分法
题目描述 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 搜索一个给定的目标值,如果数组中存在这 ...
- Gin框架 - 项目目录
概述 今天给大家分享,在 API 端使用 Gin 框架时,项目的目录. 目录 ├─ Project Name │ ├─ config //配置文件 │ ├── ... │ ├─ controller ...
- Ansible16:Playbook高级用法
目录 本地执行 任务委托 任务暂停 滚动执行 只执行一次 设置环境变量 交互式提示 本地执行 如果希望在控制主机本地运行一个特定的任务,可以使用local_action语句. 假设我们需要配置的远程主 ...
- [转帖]CHROME开发者工具的小技巧
CHROME开发者工具的小技巧 https://coolshell.cn/articles/17634.html 需要仔细学习看一看呢. 2017年01月19日 陈皓 评论 58 条评论 64,08 ...
- lombok的介绍、使用、简单分析和插件
学习下Lombok. 关于POJO Java面向对象编程中的特性中有封闭性和安全性.封闭性即对类中的域变量进行封闭操作,即用private来修饰他们.如此一来,其他类就不能对该变量访问了.这样,我们就 ...
- Prometheus PromSQL 常用资源
Prometheus PromSQL 常用资源 PromSQL 使用 运算乘:*除:/加:+减:- 函数 sum() 函数:求出找到所有value的值 irate() 函数:统计平均速率 by (标签 ...
- Problem 1059 老师的苦恼
Bob写文章时喜欢将英文字母的大小写混用,例如Computer Science经常被他写成coMpUtEr scIeNce,这让他的英文老师十分苦恼,现在请你帮Bob的英文老师写一个程序能够将Bob的 ...
- 插件油泼猴+脚本 for chrome 安装 - https://greasyfork.org/zh-CN
http://chromecj.com/utilities/2018-09/1525.html 一.将 *.crx 改名为 *.zip 二.访问 chrome://flags/#extensions- ...