solid-principles

Android - Can't Apply Decorator Pattern on Activities?

荒凉一梦 提交于 2019-12-11 15:01:56
问题 I would like to be able to dynamically build an Activity that has a few of the capabilities that we have (such as prevent scrolling, monitors internet connectivity, prevent orientation change, etc.). We don't want to have to create an abstract BaseActivity that contains all possible properties and abstract methods for all capabilities. We would have a lot of empty function implementations in subclasses of BaseActivity who only need to actually implement a few of those functions. Worse yet, if

How to handle different responsibilities while using only one instance of DbContext

我只是一个虾纸丫 提交于 2019-12-11 11:16:17
问题 I have been looking around for an answer to my question but couldn't find one, mostly because I don't really know how to phrase it! I am playing around with EF code first and trying to implement some sort of repository pattern whilst using dependency injection (thanks to Unity). I am also trying to keep to SOLID (well, the SRP part at least) in that I have IStaffRepository and IDepartmentRepository interfaces which in turn implement IRepository<TEntity> which provides basic CRUD methods. My

Possible help in code refactoring

假装没事ソ 提交于 2019-12-11 10:29:52
问题 Sandi Metz says in SOLID OOPS concepts from GORUCO that presence of if..else blocks in Ruby can be considered to be a deviation from Open-Close Principle . What all methods can be used to avoid not-urgent if..else conditions? I tried the following code: class Fun def park(s=String.new) puts s end def park(i=Fixnum.new) i=i+2 end end and found out that function overloading does not work in Ruby. What are other methods through which the code can be made to obey OCP? I could have simply gone for

wcf best design principles

烈酒焚心 提交于 2019-12-11 08:04:59
问题 I am looking to make some changes to an existing WCF service. I wanted to know if it would be best to make super methods such as a Save() that would use the values received to decide what action to take or if I should break the actions out into their own methods and expose those for the consumer to decide when to call them. For instance, I have a payment handler that receives notifications from our merchant when they make a payment attempt and its results. Would it be better for me to allow

A controller that might violate Single Responsibility Principle?

两盒软妹~` 提交于 2019-12-11 03:47:56
问题 Referring to this comment, When a class has a very long list of arguments, it can be a "code smell" that your class is trying to do too much and possibly not following the single responsibility principle. If your class is trying to do too much, consider refactoring your code into a number of smaller classes that consume each other. What should I do about this controller class below - is it "trying to do too much"? class Controller { public $template; public $translation; public $auth; public

Refactor with strategy pattern and then apply SOLID principle

落花浮王杯 提交于 2019-12-11 02:55:54
问题 I have a C# class like below in an app, and looking at ways to refactor it. The Send method does not exist in the class. This is the solution that I came up with. There will be more email types in the future. I don't know whether I can apply the SOLID Open/Closed principle here because adding a new emailtype require this class to be modified. The Consumer of this service should not be concerned about the business logic, but just to know only the new emailType and the customerId . The consumer

Overriding without calling parent method, violating Liskov Principle

﹥>﹥吖頭↗ 提交于 2019-12-11 00:59:10
问题 I am developing a simple project. And I have a conflict with meaning of Liskov Principle in my project. I simplified my question of my project with this example: public class Animal { public void feed() { // do something here } } public class Dog extends Animal { // some methods and attributes @Override public void feed() { // never call parent feed() method (super.feed()) } } So, my question is, if I don't call parent method and write a completely new codes in override method, Is this

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

两盒软妹~` 提交于 2019-12-10 10:26:20
问题 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

What is a Refused Bequest?

孤街浪徒 提交于 2019-12-10 01:36:41
问题 Could someone please explain what does Refused Bequest means? I tried reading some articles and says its a kind of code smell or in wiki it tells that it is a class that overrides a method of a base class in such a way that the contract of the base class is not honored by the derived class. But in a nutshell or in a more simple terms, what is it actually? 回答1: I think you get it. Refused Bequest is a code smell. But, what type of code smell? Quoting Martin Fowler's book Refactoring: improving

Confused about Single Responsibility Principle in the following example

给你一囗甜甜゛ 提交于 2019-12-09 06:14:53
问题 In the following video, the author takes an existing class and assigns the Single Responsibility Principle to it. He takes a Print Class that has the job of Accessing Data, Formatting, and Printing the report. He breaks up each method to its own class, so he creates a DataAccess class to handle data access, he creates a ReportFormatter class to handle the formatting of the Report, and he creates a ReportPrinter class to handle the printing of the Report. The original Report class is then left