Tagged Questions
-3
votes
1answer
62 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
76 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 ...
10
votes
2answers
400 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
344 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
190 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
227 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 ...
16
votes
5answers
986 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
210 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
219 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
417 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
7answers
729 views
Using functions as a way to stylize
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
187 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 ...
5
votes
6answers
524 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
407 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
314 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
303 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
249 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
800 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 ...