solid-principles

Liskov substitution principle - no overriding/virtual methods?

荒凉一梦 提交于 2019-11-29 19:36:14
My understanding of the Liskov substitution principle is that some property of the base class that is true or some implemented behaviour of the base class, should be true for the derived class as well. I guess this would mean when a method is defined in a base class, it should never be overrided in the derived class - since then substituting the base class instead of the derived class would give different results. I guess this would also mean, having (non-pure) virtual methods is a bad thing? I think I might have a wrong understanding of the principle. If I don't, I do not understand why is

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

Breaking SOLID Principles in multiple implementation of an Interface

好久不见. 提交于 2019-11-29 12:58:46
I am facing a problem with dependency inversion in a factory method and it is also breaking Open Closed principle. My code looks like below codes public interface IWriter { void WriteToStorage(string data); } public class FileWriter : IWriter { public void WriteToStorage(string data) { //write to file } } public class DBWriter : IWriter { public void WriteToStorage(string data) { //write to DB } } Now I an using a factory class to solve the object creation. It look like below code public interface IFactory { IWriter GetType(string outputType); } public class Factory : IFactory { public IWriter

Pattern for Creating a Simple and Efficient Value type

蓝咒 提交于 2019-11-29 02:28:17
问题 Motivation: In reading Mark Seemann’s blog on Code Smell: Automatic Property he says near the end: The bottom line is that automatic properties are rarely appropriate. In fact, they are only appropriate when the type of the property is a value type and all conceivable values are allowed. He gives int Temperature as an example of a bad smell and suggests the best fix is unit specific value type like Celsius. So I decided to try writing a custom Celsius value type that encapsulates all the

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 to implement SOLID principles into an existing project

自闭症网瘾萝莉.ら 提交于 2019-11-28 16:44:55
I apologize for the subjectiveness of this question, but I am a little stuck and I would appreciate some guidance and advice from anyone who's had to deal with this issue before: I have (what's become) a very large RESTful API project written in C# 2.0 and some of my classes have become monstrous. My main API class is an example of this -- with several dozen members and methods (probably approaching hundreds). As you can imagine, it's becoming a small nightmare, not only to maintain this code but even just navigating the code has become a chore. I am reasonably new to the SOLID principles, and

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

Configuring Automapper in Bootstrapper violates Open-Closed Principle?

喜欢而已 提交于 2019-11-28 15:19:45
I am configuring Automapper in the Bootstrapper and I call the Bootstrap() in the Application_Start() , and I've been told that this is wrong because I have to modify my Bootstrapper class each time I have to add a new mapping, so I am violating the Open-Closed Principle. How do you think, do I really violate this principle? public static class Bootstrapper { public static void BootStrap() { ModelBinders.Binders.DefaultBinder = new MyModelBinder(); InputBuilder.BootStrap(); ConfigureAutoMapper(); } public static void ConfigureAutoMapper() { Mapper.CreateMap<User, UserDisplay>() .ForMember(o =>

Application architecture/composition in F#

十年热恋 提交于 2019-11-28 15:13:23
I have been doing SOLID in C# to a pretty extreme level in recent times and at some point realized I'm essentially not doing much else than composing functions nowadays. And after I recently started looking at F# again, I figured that it would probably be the much more appropriate choice of language for much of what I'm doing now, so I'd like to try and port a real world C# project to F# as a proof of concept. I think I could pull off the actual code (in a very un-idiomatic fashion), but I can't imagine what an architecture would look like that allows me to work in a similarly flexible fashion

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),