solid-principles

SOLID principles, Repository pattern and EntityFramework cache in Asp Net Mvc

好久不见. 提交于 2019-12-05 18:34:25
I have a visual studio solution using solid pattern. I have a IRepository (Crud implementation), IDbFactory (used by a repository), IUnitOfWork. I also have services, who uses repositories to build custom querys and complex database operation. I am using also IoC pattern with Ninject. In a web mvc controller I use only services to access to database. A repository receive a IDbFactory who build a EntityFramework Context. I have some problems: In a service when i have to access to two tables for join them i should use two repositories, calling the GetAll() method of both of them. In this case

How to resolve type at run time to avoid multipe if else

一世执手 提交于 2019-12-05 08:29:47
I have my code which makes a webservice Call based on type of request. To do that , I have following code; public class Client { IRequest request; public Client(string requestType) { request = new EnrolmentRequest(); if (requestType == "Enrol") { request.DoEnrolment(); } else if (requestType == "ReEnrol") { request.DoReEnrolment(); } else if (requestType == "DeleteEnrolment") { request.DeleteEnrolment(); } else if (requestType == "UpdateEnrolment") { request.UpdateEnrolment(); } } } So as per open close principle, I can subclass like: Class EnrolmentRequest:IRequest { CallService(); } Class

How to avoid switch-case statements in Java [duplicate]

风格不统一 提交于 2019-12-05 05:23:21
This question already has answers here : Converting many 'if else' statements to a cleaner approach [duplicate] (7 answers) Closed 3 years ago . I have an enum of TriggerType, where different triggers can be added public enum TriggerType { meta,data,list,toggle } These trigger types are used inside different handlers (eg Component, Dashboard etc) to identify which trigger is triggered inside the handler through a switch-case, for eg Code snippet of ComponentHandler using trigger through switch-case is given below @Override public TriggerResultInterface executeTriggerJob(TriggerEventHelper

Are there any static analysis tools that will report how closely the SOLID principles are followed?

旧时模样 提交于 2019-12-04 21:00:39
问题 I know blindly following any "best practice" can still lead to a stinking pile of crap that strictly adheres to the best practice. The SOLID principles are just that, principles . They don't apply to every situation but they are still very good heuristics for finding possible improvements in your code. The downside to them is that they sometimes require a deep analysis of your source code to apply them. I, like most programmers, am constantly on the lookout for more efficient ways of doing

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

DDD: What kinds of behavior should I put on a domain entity?

浪子不回头ぞ 提交于 2019-12-04 16:06:55
问题 My team tries very hard to stick to Domain Driven Design as an architectural strategy. But, most of the time, our domain entities are pretty enimic. We'd like to be putting more business/domain behavior on our domain entities. For example, Active Record puts data access on the entity. We don't want that because we happily use the repository pattern for data access. Also, we design our software to be SOLID (the five software design principles that Uncle Bob put together). So, it's important to

When adhering to Liskov Substitution Principle (LSP) can a child class implement additional interface?

余生长醉 提交于 2019-12-04 15:49:53
问题 Consider this ruby example class Animal def walk # In our universe all animals walk, even whales puts "walking" end def run # Implementing to conform to LSP, even though only some animals run raise NotImplementedError end end class Cat < Animal def run # Dogs run differently, and Whales, can't run at all puts "running like a cat" end def sneer_majesticly # Only cats can do this. puts "meh" end end Does method sneer_majesticly violate LSP, being defined only on Cat, since this interfaces is

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,

How does the SOLID open/closed principle fit in with Dependency Injection and dependency inversion

限于喜欢 提交于 2019-12-04 14:22:14
问题 I am starting to apply SOLID principles, and am finding them slightly contradictory. My issue is as follows: My understanding of dependency inversion principle is that classes should depend on abstractions. In practice this means classes should be derived from interfaces. All fine so far. Next my understanding of the open/closed principle is that after a certain cut off point, you should not alter the contents of a class, but should extend and override. This makes sense so far to me. So given

Dependency Inversion Principle and where to put the interfaces

不打扰是莪最后的温柔 提交于 2019-12-04 12:49:53
I am building a simple MVC application in asp.net. I want to follow the dependency inversion principle and I don't know if I am doing it right. I am currently working on the Authentication system. I have an AccountController which uses the Authenticator service inside. The Authenticator service is injected into the controller by constructor injection. public class AccountController : Controller { private IAuthenticator _authenticator; public AccountController(IAuthenticator authenticator) { _authenticator = authenticator; } // // POST: /Account/Login [HttpPost] public ActionResult Login