refactoring

How refactor two methods which are very similar

别等时光非礼了梦想. 提交于 2020-03-03 04:50:46
问题 I have following classes: public interface IBaseInterface { String baseMethod(); } public class BaseClass implements IBaseInterface{ @Override public String baseMethod() { return "baseInterface"; } public String otherBaseMethod(){ return "otherBaseMethod"; } } public class ClassA implements IBaseInterface{ @Override public String baseMethod() { return "ClassA"; } public String getAttribiuteA(){ return "A"; } } public class ClassB implements IBaseInterface { @Override public String baseMethod(

Parallel Inheritance Hierarchy Refactoring

蓝咒 提交于 2020-02-23 08:45:31
问题 I'm dealing with a Parallel Inheritance Hierarchy and I have an idea for a step by step refactoring and would like opinions on whether it will work or whether there is a better way to do it. Create a Handler class with children that implement the specific behavior required e.g CarHandler with children vwHandler , fordHandler , bmwHandler Add calls to all the components and restructure it so that the children return the objects neccessary. e.g. Call vwHandler.getDrive will return the result of

refactoring when two functions share some similarity

我与影子孤独终老i 提交于 2020-02-15 23:07:20
问题 I have two tabs in my app one is a player tab and another is a coaching tab. I have a function1 in the player tab and function2 in the coaching tab. function1 var beforeList = $('#players').val() $('#players').change(function () { var afterList = $(this).val() var selectedPlayer = '' if (!beforeList) { selectedPlayer = afterList[0] $('parent option[value=' + selectedPlayer + ']').add() $('#injuredPlayer option[value=' + selectedPlayer + ']').add() } else if (!afterList) { selectedPlayer =

Why are “Extracted Interfaces” Internal rather than Public?

孤人 提交于 2020-02-04 05:32:05
问题 Visual Studio includes a refactoring function called "Extract Interface" that generates an interface based on a class implementation. The extracted interfaces are Internal by default. Problem is, we end up changing nearly all of them to Public . Does anyone know why it's Internal by default? Better yet, is there a way to customize this to default to Public ? 回答1: It might work if you change the Visual Studio template for interfaces (I haven't tried that but assume this should work). For

How to substitute switch statement with better solution - clean code hints

偶尔善良 提交于 2020-01-30 06:43:06
问题 I created a code, which have to convert ContentDataType into MIME types. For example - ContentDataType is a simple String like ImageJPEG and now I use MediaType.IMAGE_JPEG_VALUE to convert it into image/jpeg . But I use switch to do this. This is a code: public static String createContentType(ContentDataType contentDataType) { String contentType; switch (contentDataType) { case IMAGE_JPG: contentType = MediaType.IMAGE_JPEG_VALUE; break; //next media types } return contentType; } What is a

nodejs: Node modules vs singleton classes

孤者浪人 提交于 2020-01-23 07:29:16
问题 PRE: I've read NodeJS modules vs classes but this is more specific. As part of some refactoring in Node I have a couple of Application Services (in DDD-terminology) which are technically implemented as Node modules. Since (in a DDD-world, an probably any other for that matter) Application Services should be singletons and since Node modules are guaranteed to be 1 'instance' only, it seems to me that this is an okay fit (modules trivially implement the 'singletonness') Is there any reason why

Refactoring package name breaks entire app

吃可爱长大的小学妹 提交于 2020-01-22 17:27:10
问题 I am trying to refactor my package using Eclipse org.sheehan.activity to org.sheehan.stocks.activity For some reason my project just blows up when I do this and R doesn't get regenerated. How can I refactor properly? UPDATE : I updated my Android Manifest to reflect the change. R still doesn't get regenerated. Even after a clean. The compiler is complaining about org.sheehan.activity.R 回答1: I resolved by: Android Tools > Rename Package Application 回答2: If you renamed properly, all your

Refactoring package name breaks entire app

女生的网名这么多〃 提交于 2020-01-22 17:27:07
问题 I am trying to refactor my package using Eclipse org.sheehan.activity to org.sheehan.stocks.activity For some reason my project just blows up when I do this and R doesn't get regenerated. How can I refactor properly? UPDATE : I updated my Android Manifest to reflect the change. R still doesn't get regenerated. Even after a clean. The compiler is complaining about org.sheehan.activity.R 回答1: I resolved by: Android Tools > Rename Package Application 回答2: If you renamed properly, all your

R language aware code reformatting/refactoring tools?

三世轮回 提交于 2020-01-22 17:16:30
问题 Recently I've found myself working with R code that is all over the map in terms of coding style - multiple authors and individual authors who aren't rigorous about sticking to a single structure. There are certain tasks that I'd like to automate better than I currently do. I'm looking for a tool (or tools) that manage the following tasks - listed in increasing order of desire but also somewhat in increasing order of skepticism of existence. Basic formatting. Things like converting "if( foo )

Javascript source code analysis ( specifically duplication checking )

浪子不回头ぞ 提交于 2020-01-21 08:33:11
问题 Partial duplicate of this Notes: I already use JSLint extensively via a tool I wrote that scans in intervals my current project directory for recently updated/created .js files. It's drastically improved productivity for me and I doubt there is anything as good as JSLint for the price (it's free). That said, is there any analysis tool out there that can find repetitive or near-duplicate code blocks, the goal being to make it easier to find opportunities to consolidate large files or small