solid-principles

Is adding a class that inherits from something a violation of the solid principles if it changes the behavior of code?

£可爱£侵袭症+ 提交于 2020-01-09 07:40:26
问题 I struggled to enable my code to run code first EF migrations using different connection strings, and finally got it working. The method I used is outlined in my answer to this question What bothers me is that in order to be able to run the same code using different connection strings I had to 1) Resort to a global setting to store the connection string 2) Introduce a class whose very presence caused the code to behave differently. This is so different to the way I am used to working. Is the

Select micro services vs library as dependency?

╄→гoц情女王★ 提交于 2020-01-06 02:12:06
问题 I have two modules(mod1 with DB1 and mod2 with DB2) hosted as microservices. Both modules have some common functionality which can interact with DB1 and DB2 both. Approach_1:- Make another mod3 as shared library jar for common component and inject it in both modules to avoid duplication of code Approach_2:- Make another micro service for common component instead of shared library jar. Not sure which approach is better in term of design and what criteria I need to consider here? Per my

Make code more Generic in Java

与世无争的帅哥 提交于 2020-01-05 04:29:23
问题 I have a Trigger Manager scenario where I delegate the triggers (in other-words subscribe triggers) to different handlers . For now I have three handler types, I use a switch-case with enum (enum here is the handler type) to redirect to correct handler. But my code seems not extensible, its not generic and it doesn't follow SOLID principle. Imagine if I need to have more handler I will be eventually coming and editing my switch case code and I will have more cases where it affects the

Clean Code - Are output parameters bad?

丶灬走出姿态 提交于 2020-01-05 03:18:11
问题 I was looking at a former colleagues post. He quoted something from an article "In Clean Code Bob Martin disparages output arguments, saying “In general output arguments should be avoided.” My current code base is C#. I am working in a rather large application. It was written primarily in procedural style often breaking SOLID principles. When I have the opportunity I often will break some of the methods that violate single responsibility principle into separate methods. At times I'll create

design pattern advice: graph -> computation

你说的曾经没有我的故事 提交于 2020-01-04 05:25:16
问题 I have a domain model, persisted in a database, which represents a graph. A graph consists of nodes (e.g. NodeTypeA, NodeTypeB) which are connected via branches. The two generic elements (nodes and branches will have properties). A graph will be sent to a computation engine. To perform computations the engine has to be initialised like so (simplified pseudo code): Engine Engine = new Engine() ; Object ID1 = Engine.AddNodeTypeA(TypeA.Property1, TypeA.Property2, …, TypeA.Propertyn); Object ID2

Configuring Automapper in Bootstrapper violates Open-Closed Principle?

我们两清 提交于 2019-12-29 02:23:05
问题 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();

Simulate Inheritance by Extension

社会主义新天地 提交于 2019-12-24 16:25:02
问题 I have a library of classes that describe different pieces of connecting hardware such as nails, screws and bolts that we will call the ConnectorLibrary. I am attempting to build a library on top of that one that will handle analyzing the grip capacity of each class in that library that we will call ConnectorGripAnalysisLibrary. For this question we will work with the classes: Screw , Bolt , and Connector . Both Screw and Bolt inherit from Connector (which is an abstract class) and they are

polymorphic extension to 3rd party classes

别说谁变了你拦得住时间么 提交于 2019-12-24 16:22:54
问题 I have a situation where I have an IEnumerable which I need to iterate through and execute some code against each item. This code to be executed is dependent on the actual type of the item, and what I am looking for is a good clean way of doing this without any conditionals, so if the number of derived types I need to handle increases I simply need to write a new handler and not change any of my existing code. To illustrate this I have the example where the 3rd party library contains the

classes with CRUD methods violating Single Responsibility principle?

 ̄綄美尐妖づ 提交于 2019-12-24 00:38:37
问题 I am trying to understand single responsibility principle. I have following questions. The Single Responsibility Principle (SRP) states that there should never be more than one reason for a class to change. Usually our Resource,Service and Repository classes have create,read,update and delete method. We are changing each class to modify code for any any of these operations. Is it violating SRP? Do we need separate class for each action? When I run sonar lint, I have seen below message.

Using a Func<> over an interface?

非 Y 不嫁゛ 提交于 2019-12-23 08:53:09
问题 I have an already existing generic class public class Foo<T> { private T _item; public Foo(T item){ _item = item;} } I have to create a method which will return a certain property of T. I see two solutions here. Creating an interface : public const string TestVar = "bar"; public interface INamable { string Name { get; } } public class Bar : INamable { public string Name { get { return TestVar; } } } public class Foo<T> where T : INamable { private T _item; public Foo(T item) { _item = item; }