single-responsibility-principle

Are Laravel facades dependencies?

风流意气都作罢 提交于 2019-12-07 12:51:43
问题 I have read that there should be not too much dependencies to one class. In one book, it states that 4 dependencies might be a sign that class might be doing too much. Lets say I have written a class which uses 10 dependencies: 6 classes and 4 facades. Should I care only about those 6 classes and split them, or care about 4 facades too? If somebody want to know how I get so many facades: use Input; use App; use Session; use Log; Those all are needed often. I have heard question - why do I

Single Responsibility and Mixins

给你一囗甜甜゛ 提交于 2019-12-07 02:11:46
问题 Given that Mixins generally introduce new behaviour into a class, this generally implies that a class would have more than one behaviour. If a class has a single responsibility this is defined as the class having only one reason for change. So, I can see this from two different perspectives The class only has one reason for change. The module mixed in also has only one reason for change. If the class is changed only the class will need retesting. If the module is changed only the module needs

Understanding the practical benefits of using the Single Responsibility Principle

可紊 提交于 2019-12-06 17:52:37
问题 I'm trying to understand the SRP but, whilst I understand the reasoning behind how to apply it, I'm not really seeing the benefit of doing so. Consider this example, taken from Robert Martin's SRP PDF: interface IModem { void Dial(string number); void Hangup(); void Send(char c); char Recv(); } He proposes separating this into two interfaces: interface IModemConnection { void Dial(string number); void Hangup(); } interface IModemDataExchange { void Send(char c); char Recv(); } I've also been

RubyMotion async programming with BubbleWrap

天大地大妈咪最大 提交于 2019-12-06 06:23:37
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.json", {cookie: authCookie}) do |response| projects = JSON.parse(response.body.to_str) projects

Are Laravel facades dependencies?

拟墨画扇 提交于 2019-12-05 20:02:20
I have read that there should be not too much dependencies to one class. In one book, it states that 4 dependencies might be a sign that class might be doing too much. Lets say I have written a class which uses 10 dependencies: 6 classes and 4 facades. Should I care only about those 6 classes and split them, or care about 4 facades too? If somebody want to know how I get so many facades: use Input; use App; use Session; use Log; Those all are needed often. I have heard question - why do I need App? To call a function: App::setLocale('lt'); Some say that facades are not dependencies, also in

Single Responsibility and Mixins

喜你入骨 提交于 2019-12-05 08:00:59
Given that Mixins generally introduce new behaviour into a class, this generally implies that a class would have more than one behaviour. If a class has a single responsibility this is defined as the class having only one reason for change. So, I can see this from two different perspectives The class only has one reason for change. The module mixed in also has only one reason for change. If the class is changed only the class will need retesting. If the module is changed only the module needs retesting. Hence, SRP is intact. The class now has two reasons for change. If the class is changed,

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

坚强是说给别人听的谎言 提交于 2019-12-05 01:26:21
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 its properies. Next requirement is to have possibility to store this object data in some storage object

Write programs that do one thing and do it well

依然范特西╮ 提交于 2019-12-04 19:17:59
问题 I can grasp the part "do one thing" via encapsulation, Dependency Injection, Principle of Least Knowledge, and You Ain't Gonna Need It; but how do I understand the second part "do it well?" An example given was the notion of completeness , given in the same YAGNI article: for example, among features which allow adding items, deleting items, or modifying items, completeness could be used to also recommend "renaming items". However, I found reasoning like that could easily be abused into

Implementation of Single Responsibility Principle

拥有回忆 提交于 2019-12-04 14:26:05
问题 If I break my Objects down to 'Single Responsibilities', is there a fundamental thought whether like objects should live together or separately, for example if I have class Employee_DataProvider() : IEmployee_DataProvider { ... }; class Employee_Details() : IEmployee_Details { ... }; class Employee_Payroll() : IPayroll() { ... }; class Employee_LeaveProcessing() : ILeaveProcessing_Client { ... }; ... Is it bad smell to have all these living inside, yet loosely coupled to through interfaces,

Does implementing multiple interfaces violate Single Responsibility Principle?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 10:26:31
问题 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? 回答1: 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