solid-principles

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

Dependency Inversion Principle (SOLID) vs Encapsulation (Pillars of OOP)

╄→尐↘猪︶ㄣ 提交于 2019-12-02 14:22:55
I was recently having a debate about the Dependency Inversion Principle , Inversion of Control and Dependency Injection . In relation to this topic we were debating whether these principles violate one of the pillars of OOP, namely Encapsulation . My understanding of these things is: The Dependency Inversion Principle implies that objects should depend upon abstractions, not concretions - this is the fundamental principle upon which the Inversion of Control pattern and Dependency Injection are implemented. Inversion of Control is a pattern implementation of the Dependency Inversion Principle,

Writing JavaScript according to SOLID

余生颓废 提交于 2019-12-02 14:03:28
Have any one used the SOLID programming principle (or any of it's parts) while developing JavaScript? I've just started up on reading on it but can't seem to find anyone that used it for JS. The only part I find easy to implement/use is the "Single responsibility principle". What I'm looking for is articles or example where these principles are used. And are there any argument's why one shouldn't use some parts? For example the "Interface segregation principle" says that "the notion that many client specific interfaces are better than one general purpose interface." But from my knowledge there

Change current implementation of basic MVVM to adhere to SOLID pattern

拥有回忆 提交于 2019-12-02 13:11:51
问题 I have been writing all my MVVM application with basic design pattern generally mentioned in MVVM examples available online. The pattern that I am following is described below: Model This section include DTO classes with their properties and Interfaces IDataService and like: public class Employee { public string EmployeeName { get; set; } public string EmployeeDesignation { get; set; } public string EmployeeID { get; set; } } public interface IDataService { public Task<Employee>

Does this solve the Liskov Substitution square-rectangle violation?

邮差的信 提交于 2019-12-01 23:26:21
问题 I'm very new to the SOLID design principles. One thing I had problem with understanding is the "Square-rectangle" example of a Liskov Substition Principle violation. Why should the Height/Width setter of a Square override the ones of a Rectangle? Isn't this exactly what's causing the problem when there's Polymorphism? Doesn't removing this solve the problem? class Rectangle { public /*virtual*/ double Height { get; set; } public /*virtual*/ double Width { get; set; } public double Area() {

How to build the ViewModel in MVVM not to violate the Single Responsibility Principle?

别来无恙 提交于 2019-12-01 15:22:25
Robert Martin says: "There should never be more than one reason for a class to change" . Let's consider the ViewModel class which is bound to a View. It is possible (or even probable) that the ViewModel consists of properties that are not really related to each other. For small views the ViewModel may be quite coherent, but while the application gets more complex the ViewModel will expose data that will be subject to change for different and unrelated reasons . Should we worry about the SRP principle in the case of ViewModel class or not? gcores The ViewModel single responsibility is to

How to build the ViewModel in MVVM not to violate the Single Responsibility Principle?

痴心易碎 提交于 2019-12-01 14:09:16
问题 Robert Martin says: "There should never be more than one reason for a class to change" . Let's consider the ViewModel class which is bound to a View. It is possible (or even probable) that the ViewModel consists of properties that are not really related to each other. For small views the ViewModel may be quite coherent, but while the application gets more complex the ViewModel will expose data that will be subject to change for different and unrelated reasons . Should we worry about the SRP

Inject require object depends on condition in constructor injection

♀尐吖头ヾ 提交于 2019-12-01 12:30:49
I have an interface public interface ITrnsitReport { List<UserDefinedType> GetTransitReportData (); } And it has only one implementation which is public class TransitReport : ITrnsitReport { private IValidateInput _inputValidation = null; private readonly ITransitRepository _transitRepo = null; public TransitReport (IValidateInput inputValidation, ITransitRepository transitRepo) { _inputValidation = inputValidation; _transitRepo = transitRepo; } public List<UserDefinedType> GetTransitReportData (string input1, string input2) { List<UserDefinedType> ppdcReportList = null; bool isValid =

Can good Object Orientated Design be formalised as good relational database design has been?

荒凉一梦 提交于 2019-12-01 06:30:22
In the database world, we have normalisation. You can start with a design, crank the steps and end up with a normal form of the database. This is done on the basis of the semantics of the data and can be thought of as a series of design refactorings. In object orientated design, we have the SOLID principals and various other adhoc guidelines towards good design. Do you think it is possible to define the equivalent of normal forms for OO, such that a series of refactoring steps could move a procedural piece of code (or poorly factored OO design) into a correct (in some well-defined sense)

What is the One Class, One Responsibility Principle?

半世苍凉 提交于 2019-12-01 05:13:15
I would like to learn about the One Class, One Responsibility principle. I have found some articles about it, but without examples. It would help me if you can give me an example of a class that violates the principle. I'm familiar with the idea that a method should do only one thing, for instance get and set methods. It must not be the same as One Class, One Responsibility , because set and get methods are both implemented inside a class. So does this mean the class is violating the rule because the class has responsibilities both to set and to get? What is the One Class, One Responsibility