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 ......
单一职责原则(The Single Responsibility Principle) 开放/关闭原则(The Open Closed Principle) 里氏替换原则(The Liskov Substitution Principle) 依赖倒置原则(The Dependency Inversion 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 ...
Single Responsibility Principle (SRP) Open/Closed Principle (OCP) Liskov Substitution Principle (LSP) a.k.a. Design by Contract Dependency Inversion Principle (DIP) Interface Segregation Principle ...
High-quality Motion Deblurring from a Single Image.pdf
单一职责原则(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
1、单一职责原则单一职责原则(SRP:Single responsibility principle)又称单一功能原则,面向对象五个基本原则(SOLID)之一
图片AI合成人脸 Avatar Maker Pro - 3D avatar from a single selfie
Super-Resolution from a Single Image算法原理整理_思维导图 https://blog.csdn.net/Lininggggggg/article/details/106499469
微软研究院的最新大作。 We describe two new approaches to human pose estimation. Both can quickly and accurately predict the 3D positions of body jointsfromasingledepthimage,...
去雾 灰度图 Fast Visibility Restoration from a Single Color or Gray Level Image
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.
Learning to Estimate 3D Hand Pose from Single RGB Images
单一职责原则 srp(Single Responsibility Principle) 2. 里氏替换原则 lsp(Liskov Substitution Principle) 3. 依赖倒置原则 dip(Dependence Inversion Principle) 4. 接口隔离原则 isp(interface-segregation ...
不错的一本计算机视觉书籍,收藏
depth-map-prediction-from-a-single-image-using-a-multi-scale-deep-network.pdf
单一职责原则(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 ...