0
votes
1answer
138 views

Is there a Pattern or a Refactoring Method to pull data-loading out of existing Class

I am refactoring legacy codebase. Part of it is a loadProduct() function inside a larger "everything" class. loadProduct() loads data from a database. I want to move this loading-data part out of ...
1
vote
3answers
138 views

How do I evaluate if an Orchestration is the appropriate design pattern for a given problem?

Say that you're doing a code review, and you find yourself faced with an orchestration pattern: class OrchestrationClass { private Configuration _configuration; private DataStore1 _dataStore1; ...
0
votes
2answers
352 views

Refactorable God v.s. too many classe [duplicate]

So I have this problem: in order to structure my code hierarchically, for every new tiny thing, I create a separate sub-folder, file, class ... and in it one 10-line function. It is an anti-pattern. ...
3
votes
4answers
714 views

Get rid of long/Complex if..else statements using Chain of Responsibility?

I've an HttpHandler, which allows users to login to a system by passing in an encrypted code. Inside the ProcessRequest it performs quite a few steps. Retrieve the encrypted code from request ...
2
votes
2answers
325 views

Refactored to a fancy global variable?

I am currently refactoring an application that i built in JavaScript. The application uses a starting hour and a total working hour count in order to construct a timetable for daily, weekly and ...
3
votes
2answers
78 views

How to refactor to cleaner version of maintaing states of the widget

Backstory I inherited a bunch of code that I'd like to refactor. It is a UI application written in javascript. Current state: We have main application which consist of several UI components. And ...
-3
votes
1answer
94 views

Refactoring methods with the same behavior [closed]

Imagine you have 2 methods : GetConsolidation([...]); GetReportOfConsolidation([...]); These 2 methods use the same "behavior" (some local variables assigned with data) like : var data = ...
0
votes
1answer
782 views

Introducing Fowler's Table Data Gateway to refactor poorly designed systems

I am developing an application, which currently has about 150,000 lines of code. The previous developer didn't really use any discipline when writing code. Application is in production but is ...
12
votes
2answers
600 views

I should have used a factory method instead of a constructor. Can I change that and still be backwards-compatible?

The problem Let's say I have a class called DataSource which provides a ReadData method (and maybe others, but let's keep things simple) to read data from an .mdb file: var source = new ...
5
votes
2answers
398 views

When is it inappropriate to make objects immutable?

I have a class which represents an entity object in our system (for sake of argument, a Customer object) public class Customer() { private int id; private String name; ... // 30+ fields ...
4
votes
3answers
211 views

Using the mouse as a multi-tool creates heavy conditional logic for executing commands, how do I change this?

The feature is in many different types of editing programs where a mouse click may have completely different commands to execute (using the Command Pattern) Currently I have an overarching ...
4
votes
3answers
274 views

How to refactor “nested” view classes to avoid deep method calls?

Lets say I'm displaying a bunch of data (model) using a View class for rendering. However, a lot of the data has sub-data (models) complicated enough to require separate rendering classes. In my ...
21
votes
6answers
1k views

How do I prevent unknowningly duplicating code?

I work on a rather large code base. Hundreds of classes, tons of different files, lots of functionality, takes more than 15 minutes to pull down a fresh copy, etc. A big problem with such a large ...
0
votes
2answers
235 views

Question on refactoring and code design

Suppose, I have a class with a constant static final field. Then I want in certain situations that field to be different. It still can be final, because it should be initialized in constructor. My ...
4
votes
2answers
265 views

What is the right way to group this project into classes?

I originally asked this on SO, where it was closed and recommended that I ask it here instead. I'm trying to figure out how to group all the functions necessary for my project into classes. The goal ...
9
votes
4answers
650 views

How to unit test a function that is refactored to strategy pattern?

If I have a function in my code that goes like: class Employee{ public string calculateTax(string name, int salary) { switch (name) { case "Chris": ...
13
votes
5answers
1k views

Using functions as a way to stylize [closed]

Have you ever broken up a large function into smaller functions knowing that those smaller functions will not be called by more than one caller? The primary purpose of a function is to promote code ...
3
votes
2answers
199 views

How long does one have to wait to consider design change in code?

I had a few days ago. I was having trouble with threads. Had lots of questions asked on StackOverflow and honestly for the first time I did not get the answer I was looking for. Finally, I decided to ...
8
votes
6answers
750 views

What are the practical ways to implement the SRP?

Simply what are the practical techniques people use to check if a class violates the single responsibility principle? I know that a class should have only one reason to change, but that sentence is ...
2
votes
2answers
638 views

Right design pattern to use StopWatch class

I have to measure execution time for a blocks of code. I had implemented simple StopWatch class like http://www.goldb.org/stopwatchjava.html. If I will invoke methods of StopWatch class directly ...
3
votes
2answers
540 views

What are some good small-scale refactoring tests?

I'm looking to test potential candidates on their ability to develop concise, reusable code. I feel like a good test of that skill would be to give them a very small scale application or class ...
3
votes
1answer
334 views

Splitting Logic, Data, Layout and “Hacks”

Sure, we all heard of programming patterns such as MVVM, MVC and such. But that isn't really what I'm looking into as Layout, Data and Logic is already pretty much split up (XML-Layout markup, ...
2
votes
1answer
327 views

Most frequently used design patterns in refactoring (my example) [closed]

I've been doing quite a lot of refactoring of C++ and C# code recently, and found that 90% of the patterns I use are: Template method Factory Singleton Are these generally the most commonly used ...
5
votes
3answers
2k views

How can I practice design patterns and refactoring in a deliberate way?

I was reading the book Refactoring to patterns and was wondering how I can get chance to practice the skills, because without deliberate practice on new ways to refactor and use patterns, my skills ...