In object-oriented programming, the single responsibility principle states that every object should have a single responsibility, and that all its services should be narrowly aligned with that responsibility.
The term was introduced by Robert C. Martin in an article by the same name as part of his Principles of Object Oriented Design, made popular by his book Agile Software Development: Principles, Patterns, and Practices. Martin described it as being based on the principle of cohesion, as described by Tom DeMarco in his book Structured Analysis and Systems Specification.
Martin defines a responsibility as a reason to change, and concludes that a class or module should have one, and only one, reason to change. As an example, consider a module that compiles and prints a report. Such a module can be changed for two reasons. First, the content of the report can change. Second, the format of the report can change. These two things change for very different causes; one substantive, and one cosmetic. The single responsibility principle says that these two aspects of the problem are really two separate responsibilities, and should therefore be in separate classes or modules. It would be a bad design to couple two things that change for different reasons at different times.
The reason it is important to keep a class focused on a single concern is that it makes the class more robust. Continuing with the foregoing example, if there is a change to the report compilation process, there is greater danger that the printing code will break if it is part of the same class.
The single responsibility principle is used in responsibility driven design methodologies like the Responsibility Driven Design (RDD) and the Use Case / Responsibility Driven Analysis and Design (URDAD).
http://en.wikipedia.org/wiki/Single_responsibility_principle
分享到:
相关推荐
The Dependency Inversion The Interface Segregation The Open-Closed Principle The Single Responsibility Principle ......
4 单一职责原则-Single Responsibility Principle (SRP) 5 开闭原则-The Open-Closed Principle (OCP) 二 包的设计原则 6 重用发布等价原则-Release Reuse Equivalency Principle (REP) 7 无环依赖...
1、单一职责原则【SINGLE RESPONSIBILITY PRINCIPLE】:一个类负责一项职责. 2、里氏替换原则【LISKOV SUBSTITUTION PRINCIPLE】:继承与派生的规则.(子类可替换父类) 3、依赖倒转原则【DEPENDENCE INVERSION ...
R. Fergus, B. Singh, A. Hertzmann, S. T. Roweis, and W. T. Freeman. Removing camera shake from a single photograph. ACM Trans. Graphics, 25(3):787–794, 2006.
单一职责原则(Single Responsibility Principle,简称SRP) 有且仅有一个原因引起类的变更。 里氏替换原则(Liskov Substitution Principle,LSP) 只要父类出现的地方都可以用子类替换。 依赖倒置原则...
Neuronal Dynamics From Single Neurons to Networks and Models of Cognition.pdf Neuronal Dynamics From Single Neurons to Networks and Models of Cognition.pdf
《Avatar Maker Pro - 3D avatar from a single selfie》是一个创新的软件工具,它利用先进的图像处理和3D建模技术,使用户能够通过一张简单的自拍照片创建逼真的3D头像。这款工具专为那些希望在虚拟世界中拥有个性...
图片AI合成人脸 Avatar Maker Pro - 3D avatar from a single selfie
Super-Resolution from a Single Image算法原理整理_思维导图 https://blog.csdn.net/Lininggggggg/article/details/106499469
单一职责原则 srp(Single Responsibility Principle) 2. 里氏替换原则 lsp(Liskov Substitution Principle) 3. 依赖倒置原则 dip(Dependence Inversion Principle) 4. 接口隔离原则 isp(interface-segregation ...
单一职责原则(Single Responsibility Principle,SRP):一个类应该只有一个引起它变化的原因,即一个类应该只有一个职责。这个原则鼓励将不同的功能分离到不同的类中,以减少类的复杂性,提高代码的可维护性。 ...
propose a unified framework for two tasks: automatic estimation and removal of color noise from a single image using piecewise smooth image models. We introduce the noise level function (NLF), which ...
We consider the problem of estimating detailed 3D structure from a single still image of an unstructured environment. Our goal is to create 3D models that are both quantitatively accurate as well as ...
Just a general hint: if you have to use the word “and” when describing what your class does, perhaps you should consider if it violates the Single Responsibility Principle. Let’s consider DRY for...
Avatar Maker,它是一个编辑器扩展插件,仅通过一张自拍照片即可生成3D头像。您可以直接从Unity Editor中使用现有照片或使用网络摄像头制作新照片,Avatar Maker会立即将其转换为可识别的3D化身。...
前言 Bob大叔提出并发扬了S.O.L.I.D五大原则,用来更好地进行面向对象编程,五大原则分别是: The Single Responsibility Principle(单一职责SRP) The Open/Closed Principle(开闭原则OCP) The Liskov ...
We consider the task of 3-d depth estimation from a single still image. We take a supervised learning approach to this problem, in which we begin by collecting a training set of monocular images (of ...
SOLID Principles Succinctly Published on : October 31,...Single Responsibility Principle Open-Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle
solid-php-example, 在PHP中,关于实体设计原则的一些例子 PHP中的实体原理示例 单一职责原则(Single Responsibility Principle)一个类应该有一个,并且只有一个原因来改变。 示例开闭原理类应该为扩展而打开,但...