single-responsibility-principle

Confused about Single Responsibility Principle in the following example

痞子三分冷 提交于 2019-12-03 07:38:08
In the following video , the author takes an existing class and assigns the Single Responsibility Principle to it. He takes a Print Class that has the job of Accessing Data, Formatting, and Printing the report. He breaks up each method to its own class, so he creates a DataAccess class to handle data access, he creates a ReportFormatter class to handle the formatting of the Report, and he creates a ReportPrinter class to handle the printing of the Report. The original Report class is then left with one method, Print() which calls the ReportPrinter's class method Print. DataAccess and

Does implementing multiple interfaces violate Single Responsibility Principle?

北城以北 提交于 2019-12-03 05:51:43
From Wikipedia : Single responsibility principle states that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. Does that mean implementing multiple interfaces violates this principle? I would say not by itself. A class can have one responsibility, but do multiple things in the process, and implement one interface for each set of things it needs to do to fulfill its responsibility. Also, interfaces in Java can be used to say things about what properties the class has (for example, Comparable and Serializable ), but not really

Are current MVVM view model practices a violation of the Single Responsibility Principle?

こ雲淡風輕ζ 提交于 2019-12-03 05:49:16
问题 With current practices (at least with WPF and Silverlight) we see views bound via command bindings in the view model or we at least see view events handled in view models. This appears to be a violation of SRP because the view model doesn't just model the view state, but responds to the view (user). Others have asked how to build view models without violating SRP or asked whether their implementations do so (this last is the controller in MVC, but roughly analogous). So are current practices

DDD Invariants Business Rules and Validation

﹥>﹥吖頭↗ 提交于 2019-12-03 03:49:28
问题 I am looking for advice on where to add validation rules for domain entities, and best practices for implementation. I did search and did not find what i was looking for, or i missed it. I would like to know what the recommended way is for validating that properties are not null, in a certain range, or length, etc... I have seen several ways using an IsValid() and other discussions about enforcing in the constructor so the entity is never in an invalid state, or using preprocessing and

How do you define a Single Responsibility?

回眸只為那壹抹淺笑 提交于 2019-12-03 01:39:33
问题 I know about "class having a single reason to change". Now, what is that exactly? Are there some smells/signs that could tell that class does not have a single responsibility? Or could the real answer hide in YAGNI and only refactor to a single responsibility the first time your class changes? 回答1: The Single Responsibility Principle There are many obvious cases, e.g. CoffeeAndSoupFactory . Coffee and soup in the same appliance can lead to quite distasteful results. In this example, the

Are current MVVM view model practices a violation of the Single Responsibility Principle?

穿精又带淫゛_ 提交于 2019-12-02 19:09:30
With current practices (at least with WPF and Silverlight) we see views bound via command bindings in the view model or we at least see view events handled in view models. This appears to be a violation of SRP because the view model doesn't just model the view state, but responds to the view (user). Others have asked how to build view models without violating SRP or asked whether their implementations do so (this last is the controller in MVC, but roughly analogous). So are current practices a violation of SRP? Or is "view model" really a collection of things that don't violate SRP? To frame

DDD Invariants Business Rules and Validation

泄露秘密 提交于 2019-12-02 17:15:26
I am looking for advice on where to add validation rules for domain entities, and best practices for implementation. I did search and did not find what i was looking for, or i missed it. I would like to know what the recommended way is for validating that properties are not null, in a certain range, or length, etc... I have seen several ways using an IsValid() and other discussions about enforcing in the constructor so the entity is never in an invalid state, or using preprocessing and postprocessing, and others using FluentValidation api, how invariants impact DRY and SRP. Can someone give me

How do you define a Single Responsibility?

微笑、不失礼 提交于 2019-12-02 15:09:06
I know about "class having a single reason to change". Now, what is that exactly? Are there some smells/signs that could tell that class does not have a single responsibility? Or could the real answer hide in YAGNI and only refactor to a single responsibility the first time your class changes? The Single Responsibility Principle There are many obvious cases, e.g. CoffeeAndSoupFactory . Coffee and soup in the same appliance can lead to quite distasteful results. In this example, the appliance might be broken into a HotWaterGenerator and some kind of Stirrer . Then a new CoffeeFactory and

Wierd interface method for point Iterator

谁说我不能喝 提交于 2019-12-02 11:35:34
I have to iterate over specific points of perimeter rectangle (in some cases I need to iterate over one line of this rectangle, In other cases I need to iterate over entire rectangle). I have an interface PointIterator. struct Point { double x,y } class PointIteratorI { virtual void next() =0; virtual void isOver() =0; virtual Point& getPoint() = 0; } in case of iterating over one line class LineIterator:public PointIterator { .... } in case of iterating over rectangle's perimeter class PerimeterIterator:public PointIterator { .... } In case of LineIterator I also need the type of line

Single Responsibility Principle - A hard to see example?

心已入冬 提交于 2019-12-01 19:29:09
I've just read about the Single Responsibility Principle and at one point Robert C. Martin states that it is sometimes hard to see that a class has more than one responsibility. Can anyone provide an example of such a class? Consider a HTTP class which has methods Get(URL url) SendRequest(String request) Both of these methods have to do with HTTP. However, Get and SendRequest have different levels of abstraction . Get may actually use SendRequest to send the GET request. Therefore, SendRequest should be in a low-level HTTP class, and Get should be in a high-level HTTP class which uses the low