single-responsibility-principle

What does the single responsibility principle mean for validation

梦想与她 提交于 2019-12-01 02:02:10
问题 Does the single responsibility principle mean that your validation rules should be external to the entity? If so do you use one class per validation rule? 回答1: I would normally interpret this to mean that en "entity" and the validation of an entity should be separate concerns. I would normally use a single class that can validate an entire entity, but I would see no reason to constrain its implementation by not letting that class use other classes. But I would not split validation of an

Does the traditional use of the controller in MVC lead to a violation of the Single Responsibility Principle?

纵饮孤独 提交于 2019-11-30 13:08:34
Wikipedia describes the Single Responsibility Principle this way: The Single Responsibility Principle states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. The traditional use of the controller in MVC seems to lead a programmer towards a violation of this principle. Take a simple guest book controller and view. The controller might have two methods/actions: 1) Index() and 2) Submit(). The Index() displays the form. The Submit() processes it. Do

Aren't Information Expert & Tell Don't Ask at odds with Single Responsibility Principle?

落爺英雄遲暮 提交于 2019-11-30 11:54:02
问题 Information-Expert , Tell-Don't-Ask , and SRP are often mentioned together as best practices. But I think they are at odds. Here is what I'm talking about. Code that favors SRP but violates Tell-Don't-Ask & Info-Expert: Customer bob = ...; // TransferObjectFactory has to use Customer's accessors to do its work, // violates Tell Don't Ask CustomerDTO dto = TransferObjectFactory.createFrom(bob); Code that favors Tell-Don't-Ask & Info-Expert but violates SRP: Customer bob = ...; // Now Customer

Using the Single Responsibility Principle in the “real world” [closed]

試著忘記壹切 提交于 2019-11-30 01:49:17
I basically want to get an idea of the percentage of people who think it's reasonable to use the Single Responsibility Principle in real-world code and how many actually do. In Podcast #38 Joel talks about how useless this OOP principle is the real world; and further that this demonstrates how people like Uncle Bob have likely not written non-trivial systems. I've personally written or played a big role in a few software projects but have only now come across this pattern in my young career. I love the sound of this principle and would really like to start using it. I found Joel's argument in

How do you determine how coarse or fine-grained a 'responsibility' should be when using the single responsibility principle?

被刻印的时光 ゝ 提交于 2019-11-29 20:38:15
In the SRP, a 'responsibility' is usually described as 'a reason to change', so that each class (or object?) should have only one reason someone should have to go in there and change it. But if you take this to the extreme fine-grain you could say that an object adding two numbers together is a responsibility and a possible reason to change. Therefore the object should contain no other logic, because it would produce another reason for change. I'm curious if there is anyone out there that has any strategies for 'scoping', the single-responsibility principle that's slightly less objective?

Does the traditional use of the controller in MVC lead to a violation of the Single Responsibility Principle?

孤人 提交于 2019-11-29 18:24:36
问题 Wikipedia describes the Single Responsibility Principle this way: The Single Responsibility Principle states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. The traditional use of the controller in MVC seems to lead a programmer towards a violation of this principle. Take a simple guest book controller and view. The controller might have two

How to hide logic behind a class to improve readability of method and refactor class to follow SRP?

谁都会走 提交于 2019-11-29 09:36:50
I have an algorithm to create a version for an entity and then I save that version against below 2 entity: 1) Variant 2) Category interface IEntityVersion { string GetVersion(); } public class EntityVersion : IEntityVersion { public string GetVersion() { return null; } } public interface IVariant { void Process(Variant model, string connectionString); } public abstract class BaseVariant : IVariant { private readonly IEntityVersion _entityVersion = new EntityVersion(); public void Process(Variant model, string connectionString) { try { Transform(); string variantVersion = _entityVersion

Difference between Single Responsibility Principle and Separation of Concerns

守給你的承諾、 提交于 2019-11-28 16:47:36
What is the difference between Single Responsibility Principle and Separation of Concerns? Single Responsibility Principle (SRP)- give each class just one reason to change; and “Reason to change” == “responsibility”. In example: Invoice class does not have a responsibility to print itself. Separation of Concerns (since 1974). Concern == feature of system. Taking care of each of the concerns: for each one concern, other concerns are irrelevant. Hiding implementation of behavior. From here . Matthew Groves Separation of Concern vs Single Responsibility Principle ( SoC vs SRP ) From the linked

How do you determine how coarse or fine-grained a 'responsibility' should be when using the single responsibility principle?

旧时模样 提交于 2019-11-28 16:20:08
问题 In the SRP, a 'responsibility' is usually described as 'a reason to change', so that each class (or object?) should have only one reason someone should have to go in there and change it. But if you take this to the extreme fine-grain you could say that an object adding two numbers together is a responsibility and a possible reason to change. Therefore the object should contain no other logic, because it would produce another reason for change. I'm curious if there is anyone out there that has

Does the Single Responsibility Principle work in OOP?

…衆ロ難τιáo~ 提交于 2019-11-28 10:18:26
I am struggling to understand how the Single Responsibility Principle can me made to work with OOP. If we are to follow the principle to a tee, then are we not left with many classes, many of which may just have one method each? If we don't follow the principle exactly, then what is the point in the principle? I like to state the single responsibility principle this way: "Every thing you write -- every module, class, interface, or method, should have one job. It should do the whole job and only that job. Notice that some of these things you write are big (modules), some are small (methods),