Hi Sir/Madam,
I'm doing some research in automatic refactoring suggestion. By observing the co-change pattern of some similar code, we would like to develop a tool to suggest possible refactorings to apply in order to extract out common code while parameterizing any difference between them.
I have examined the code snippets in class org.jfree.chart.plot.CombinedRangeXYPlot/CombinedRangeCategoryPlot/CombinedDomainXYPlot.
In all these classes, there is a method getSubplots(). I see these methods have exactly the same body and also experience the same changes at least once in the version history. Do you think it will be a good idea or bad idea to extract a method out of the methods?
If you would like to apply the refactoring, what will be the refactored version like? Otherwise, if you don't like the refactoring idea, would you like to share the factors in your mind which affect your decision, such as complexity of refactoring, poor readability, poor maintainability, code size, etc.? For each factor, how do you think it can affect your decision about using refactoring? If possible, any quantative analysis will be great. For example, if the code size after refactoring is greater than that before refactoring, I won't do refactoring. Or if there are only two lines shared between two code snippets, I won't do refactoring, etc.
Thanks a lot for your help! Your suggestion will be very valuable for our research.
Best regards,
Na Meng
Refactoring idea for method getSubplots()
-
- Posts: 2
- Joined: Fri Aug 29, 2014 2:19 pm
- antibot: No, of course not.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Refactoring idea for method getSubplots()
You are correct, there is scope to refactor some methods (getSubplots(), get/setGap(), getLegendItems() etc.) into a common subclass. However, the XYPlot and CategoryPlot classes diverge further up the class hierarchy for the reason that they have a different type of x-axis, so the CombinedDomainCategoryPlot and CombinedDomainXYPlot, while sharing some methods that are the same, won't have a common base class at a level where these methods could be shared (likewise for CombinedRangeCategoryPlot and CombinedRangeXYPlot).
I will probably add two new classes into the hierarchy (CombinedCategoryPlot as the base class for CombinedDomainCategoryPlot and CombinedRangeCategoryPlot, and CombinedXYPlot as the base class for CombinedDomainXYPlot and CombinedRangeXYPlot) and move the common methods into those base classes. This will still leave some duplicated methods, but in only two classes rather than four.
Thanks for your feedback.
I will probably add two new classes into the hierarchy (CombinedCategoryPlot as the base class for CombinedDomainCategoryPlot and CombinedRangeCategoryPlot, and CombinedXYPlot as the base class for CombinedDomainXYPlot and CombinedRangeXYPlot) and move the common methods into those base classes. This will still leave some duplicated methods, but in only two classes rather than four.
Thanks for your feedback.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
-
- Posts: 2
- Joined: Fri Aug 29, 2014 2:19 pm
- antibot: No, of course not.
Re: Refactoring idea for method getSubplots()
Thank a lot David for your helpful feedback. We really appreciate that.
Best regards,
Na
Best regards,
Na