single-responsibility-principle

In SOLID, what is the distinction between SRP and ISP? (Single Responsibility Principle and Interface Segregation Principle)

一世执手 提交于 2020-06-24 04:56:09
问题 How does the SOLID "Interface Segregation Principle" differ from "Single Responsibility Principle"? The Wikipedia entry for SOLID says that ISP splits interfaces which are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them However, to me that sounds like just applying the SRP to interfaces as well as classes. After all, if an interface is only responsible for just one conceptual thing, than you wouldn't be able

Doesn't having more than 1 method break the Single Responsibility Principle?

亡梦爱人 提交于 2020-03-16 06:58:58
问题 I am quite confused with the Single Responsibility Principle. The Principle states that there should only be one reason for the class to change. The problem which I am facing is, any change to a method or any logic change in doing things would change the class. For example, consider the following class: class Person{ public void eat(){ }; public void walk(){ }; public void breathe(){ }; public void run(){ }; public void driveCar(Car car){ }; } Uncle Bob describes it as there should ONLY be a

Doesn't having more than 1 method break the Single Responsibility Principle?

筅森魡賤 提交于 2020-03-16 06:55:52
问题 I am quite confused with the Single Responsibility Principle. The Principle states that there should only be one reason for the class to change. The problem which I am facing is, any change to a method or any logic change in doing things would change the class. For example, consider the following class: class Person{ public void eat(){ }; public void walk(){ }; public void breathe(){ }; public void run(){ }; public void driveCar(Car car){ }; } Uncle Bob describes it as there should ONLY be a

What is the scope of the Single Responsibility Principle? [closed]

僤鯓⒐⒋嵵緔 提交于 2020-01-28 02:43:47
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 months ago . Another engineer at my job asked me today about "what is this single responsibility thing?" and my answer was as follows: "Every scope of your code, be it an if statement, a function, a class, a module, should have one reason to change". But everywhere I read this, people

Understanding the Single Responsibility Principle

微笑、不失礼 提交于 2020-01-12 18:47:10
问题 I am quite confused on how to determine if a single method has one responsibility being done just like the following code from the book Clean Code public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e.type) { case COMMISSIONED: return calculateCommissionedPay(e); case HOURLY: return calculateHourlyPay(e); case SALARIED: return calculateSalariedPay(e); default: throw new InvalidEmployeeType(e.type); } } As the author stated on this code snippet: "... clearly does more

Understanding the Single Responsibility Principle

こ雲淡風輕ζ 提交于 2020-01-12 18:46:24
问题 I am quite confused on how to determine if a single method has one responsibility being done just like the following code from the book Clean Code public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e.type) { case COMMISSIONED: return calculateCommissionedPay(e); case HOURLY: return calculateHourlyPay(e); case SALARIED: return calculateSalariedPay(e); default: throw new InvalidEmployeeType(e.type); } } As the author stated on this code snippet: "... clearly does more

SRP applied to a workflow example: how to structure the classes in a sensible way

浪尽此生 提交于 2019-12-24 08:47:14
问题 I have a problem with deciding about class responsibilities. I have 3 html-forms: For each form there is a html template containing some text and a marker for the form to be included Each form needs to be validated, if there is an error the template and the form from (1) needs to redisplayed, together with some error messages. Only some fields are common across the different forms. If there are no errors a result message needs to be mailed. For each form there is a result mail template. I

classes with CRUD methods violating Single Responsibility principle?

 ̄綄美尐妖づ 提交于 2019-12-24 00:38:37
问题 I am trying to understand single responsibility principle. I have following questions. The Single Responsibility Principle (SRP) states that there should never be more than one reason for a class to change. Usually our Resource,Service and Repository classes have create,read,update and delete method. We are changing each class to modify code for any any of these operations. Is it violating SRP? Do we need separate class for each action? When I run sonar lint, I have seen below message.

RubyMotion async programming with BubbleWrap

狂风中的少年 提交于 2019-12-22 11:24:58
问题 I am confused with how to write decent code when using a lot of asynchronous code. In the following code snippet I log in to get the authentication cookie and use that cookie for the next request to get a list of projects name (as an example): def self.populateProjectsTable(projects_controller) payload = {email: "email", password: "pass"} HTTP.post("http://example.com/login", {payload: payload}) do |response| authCookie = response.headers['Set-Cookie'] HTTP.get("http://example.com/projects

Is Interface segregation principle only a substitue for Single responsibility principle?

自作多情 提交于 2019-12-20 09:48:45
问题 Is interface segregation principle only a substitue for single responsibility principle ? I think that if my class fulfill SRP there is no need to extract more than one interface. So ISP looks like solution in case we have to break SRP for some reason. Am I right ? 回答1: No. Take the example of a class whose responsibility is persisting data on e.g. the harddrive. Splitting the class into a read- and a write part would not make practical sense. But some clients should only use the class to