single-responsibility-principle

Wierd interface method for point Iterator

女生的网名这么多〃 提交于 2019-12-20 07:18:44
问题 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

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

十年热恋 提交于 2019-12-18 11:07:08
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I basically want to get an idea of the percentage of people who think it's reasonable to use the Single Responsibility Principle in

Polymorphism vs. division of responsibilities: how to avoid 'switching on type'

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 00:26:11
问题 In designing systems with hierarchical relationships, I often run into a problem that begs for polymorphic behavior, but there is more than one type of work that benefits from this polymorphic implementation. For instance, consider a compiler that uses an abstract syntax tree to organize the parsed source for compilation. It's convenient to organize the logic polymorphically, as you might have more than one type of ValueProvider, each of which is responsible for the emission of different code

How to apply Single Responsibility Principle to a service class

只愿长相守 提交于 2019-12-12 10:58:16
问题 Suppose we are designing a UserServiceImpl class which does CRUD (Create, Read, Update, and Delete) operations. In my view Create, Read, Update, and Delete are four reasons for a class to change. Does this class violates Single Responsibility Principle? If it violates, then should we have four classes like CreateUserServiceImpl , ReadUserServiceImpl , UpdateUserServiceImpl , and DeleteUserServiceImpl . Isn't it an overkill to have lots of classes? Suppose I define 4 interfaces each for create

Does the DAO pattern spoils cohesion /SRP?

孤者浪人 提交于 2019-12-11 05:38:41
问题 Let's use as example: class AccountDAO { create(){..} read(){..} update(){..} delete() {..} } How many responsibilities are there? 1 or 4? 回答1: SRP shouldn't be understood in a strict manner. One object should have very few responsibilities, not "one". Here AccountDAO is only responsible for Account persistence, so it has only one responsibility. 来源: https://stackoverflow.com/questions/6483392/does-the-dao-pattern-spoils-cohesion-srp

A controller that might violate Single Responsibility Principle?

两盒软妹~` 提交于 2019-12-11 03:47:56
问题 Referring to this comment, When a class has a very long list of arguments, it can be a "code smell" that your class is trying to do too much and possibly not following the single responsibility principle. If your class is trying to do too much, consider refactoring your code into a number of smaller classes that consume each other. What should I do about this controller class below - is it "trying to do too much"? class Controller { public $template; public $translation; public $auth; public

Return & print field value or just print value through class method?

北城以北 提交于 2019-12-10 14:28:51
问题 I'm currently learning Java and learning about encapsulation and I'm unsure which of the following is a better practice: Use a getter to return a field value from one class to another and then print it through a method in another class. Call a method in a class from another class to print the value of the field. The value isn't manipulated, only shown through System.out.println(); Any advice would be appreciated :) EDIT: One class (Person) holds information about people, such as name, age,

How Single Responsibility Principle relates to anemic/rich domain model?

陌路散爱 提交于 2019-12-10 01:56:32
问题 Currently in doing some code review of stuff taken over from another team and have one doubt about applying SRP and its relation to anemic or rich domain model (as defined by Martin Fowler). Rich domain model concept is to have intelligent object that can not only set/get their properties but also can perform some more complicated business logic. I wond how it fits into SRP? Say I have my model class having some properties that can expose those props and provide some simple calculations on

Confused about Single Responsibility Principle in the following example

给你一囗甜甜゛ 提交于 2019-12-09 06:14:53
问题 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

Send data in multiple ways depending on how you want to send it

我怕爱的太早我们不能终老 提交于 2019-12-08 16:37:32
问题 I have bunch of keys and values that I want to send to our messaging queue by packing them in one byte array. I will make one byte array of all the keys and values which should always be less than 50K and then send to our messaging queue. Packet class : public final class Packet implements Closeable { private static final int MAX_SIZE = 50000; private static final int HEADER_SIZE = 36; private final byte dataCenter; private final byte recordVersion; private final long address; private final