Skip to main content

All Questions

Filter by
Sorted by
Tagged with
0 votes
1 answer
813 views

Create variable of class without the parameters of it's constructor

I have a BaseClass with a constructor and some parameters and then I want to do a strategy where depending of an enum, it creates one derived class or another (of that BaseClass), but with the same ...
nautilus.g's user avatar
0 votes
1 answer
367 views

Refactor with Strategy Pattern. In Ruby

Heads up! In the below example, using a pattern is probably overkill... however, if I were extending this to count genres, count the members in a given band, count the number of fans, count the ...
AdamWeissman's user avatar
3 votes
1 answer
2k views

design pattern for switching email providers in the code

We need to send emails in our php app (who doesn't). Initially when our app was in infancy, we used simply linux sendmail. A bit moving forward we switched to our own SMTP server. That means code ...
Waku-2's user avatar
  • 1,196
0 votes
0 answers
41 views

(c# refactor) Wrapper delegator - How to call Interface method as parameter

I've to refactor old code that use a wrapper delegator for a service. This is old code: public interface IOrderService { IList<Order> GetOrders(); Order GetOrderById(int idOrder); } ...
Glauco Cucchiar's user avatar
0 votes
2 answers
374 views

How to refactor code to avoid multiple if-s [from interview]?

On interview I was asked the following question: I have following method: public void foo(SomeObject o){ if(o.matches(constant1)){ doSomething1(); }else if(o.matches(constant2)){ ...
gstackoverflow's user avatar
0 votes
2 answers
73 views

Refactoring a method for specific clients

Methods specific for customers: I try to refactore a code, where are a lot of logic for specifi customer: public void SendDocumentsToCustomer(List<Case> cases) { foreach(var case in cases) ...
user3770190's user avatar
3 votes
5 answers
400 views

How to refactor large class that uses "Strategies"?

Problem I have a large class (about 1500 LOC) and it uses different "strategies" to transform data from one object to another. I have here a representation of that class: public class FooService ...
Atif's user avatar
  • 942
0 votes
2 answers
146 views

Parsing match operator and refactoring switch cases

I need a function that will take operands/operators as parameters and provide the evaluation result. The problem that I am facing is how to elegantly parse an operator. Sample code is as below ...
Tilak's user avatar
  • 30.6k
10 votes
5 answers
9k views

Best way to do this generic abstract class in c#?

I know I'm not doing this right, but I also know there is a way to do this. I'm trying to be as generic and abstract as possible, otherwise my code is going to get real messy. So I'm using strategy ...
apexdodge's user avatar
  • 6,937
4 votes
4 answers
6k views

Alternative Pattern to Strategy

I have a piece of code where I started to put the strategy pattern in place, say as follows: IStrategy StrategyA : IStrategy StrategyB : IStrategy StrategyC : IStrategy The interface just has a ...
Mike's user avatar
  • 6,229
4 votes
4 answers
173 views

Best way to deal with conflated business and presentation code?

Considering a hypothetical situation where an old, legacy presentation library has been maintained over the years, and has gradually had more and more business logic coded into it through a process of ...
bwerks's user avatar
  • 8,941
0 votes
2 answers
576 views

Is it possible to use a Strategy pattern for data structure with no common ancestor?

I have two data structure classes (this is a simplified version of my code) Animal: Has one property “int Age” Person: Has one property “DateTime Birthday” What I am trying to accomplish is to ...
dance2die's user avatar
  • 36.9k
2 votes
3 answers
505 views

refactor help - strategy pattern

The object here is to update the UI. I normally do this on the client however this application uses the code behind. Anyways my question is I am trying to clean up these if else statements and I ...
Hcabnettek's user avatar
  • 12.9k