EFFECTS OF REFACTORING AND DESIGN PATTERNS ON THE SOFTWARE SOURCE CODE QUALITY : AN EMPIRICAL ASSESSMENT

The purpose of this research is to identify the impact of refactoring techniques and design patterns on the source code of the Data management application. The research methodology used for this research is first identify the source code bad smells and then remove them by apply refactoring techniques and design patterns. To evaluate the impact of refactoring and design patterns on the source code quality; the code metrics and visual studio 2015 community edition is used to evaluate code metrics. The results of this research shows that the applying refactoring and design patterns in a combination has a positive effect on the source code quality. The code reusability, expandability and understandability will be increased.

1. Introduction.The purpose or objective of this study is to identify the effects of refactoring and design patterns on the source code quality of Data Management application before and after applying refactoring and Design patterns.Does the source code quality improves or not?And the design patterns shall be used with thoughtfulness because they may delay the maintenance and the evaluation [6] of the source code.
The application's source code goes under this research study is named as "Data Management Application" it is a desktop base windows form application and built for in-house and server base content management.It contains different modules that are create questions, answers, explanation import export questions data on server, export data into different format (.CSV, .RTF, .SQL).Technologies used to build data management application are C#, .Net Framework 4.5.2,SQL Database.
The design patterns are used in this study are strategy, Abstract Factory, and Façade design patterns.The three quality attributes reusability, expandability and understandability used in this research study to determine the effect of design patterns on software code quality.Reusability the degree to which a module, source code or design can be reused this is an important attribute while expanding the project with the combination of existing and new requirements, expandability the degree to which a design can be extended and understandability the degree to which the source code of a project can be easily under stood by the code reviewer of maintance personnel it is also an important attribute considering source code maintance and expandability of the source code.
There are five code metrics are used to evaluate the result of this research which are maintainability Index, Cyclometic Complexity, Depth of Inheritance, Class Coupling, Line of Code.Microsoft Visual Studio 2015 community edition is used to evaluate code metrics.There are three hypotheses are presented in this research study that might be proved or disapproved after this research study.
The methodology of this research is divided into four steps.The first step is to identify the code bad smell form the source code of the application.The second step is to apply the refactoring to the code.The third step is to apply design pattern to the code.And the fourth and final step of this research is to evaluate the effects of this research by calculating the code metrics.The section I introduction contains the research question and summary of the proposal what is require: The Source Code Quality improves after applying design patterns, why does it require: it requires some quality attributes to justify the findings of this research study, and how it will be done: It will be done applying design patterns (strategy, abstract factory, and composite design patterns) on the source code of data management application.Section 2 present contains literature on topics, methods, theoretical approach Literature review section focus on what and how part of the problem what to study and how to.Section 3 focus on Proposed Methodology, research design, procedure, and hypotheses.Section 4 present the results of the research.Section 5 Conclude the research.

Literature Review.
Refactoring is a process of changing the code in such a way the behavior of the code does not change yet internal structured of the code is modified [8].A design pattern is a general repeatable solution to a commonly occurring problem in software design.A design pattern is not a finished design that can be transformed directly into code.It is a description or template for how to solve a problem that can be used in many different states [9].
Cyclomatic complexity is a code complexity measurement that is being associated to a number of coding errors.It is calculated by developing a Control Flow Graph of the code that measures the number of linearly-independent paths through a program module [7].
Maintainability Index is a software metric which measures how easy to support and change the source code is.The maintainability index is calculated as a factored formula consisting of Lines of Code, Cyclomatic Complexity and Halstead Volume.It is used in several automated software metric tools, including the Microsoft Visual Studio.[10] Depth of Inheritance The number of class definitions that extend to the root of the class hierarchy.It is more difficult to understand a method and fields that are defined or redefined when class hierarchies are deeper.[12].Class Coupling the Class coupling is how many classes are directly depended upon a class.It is good to implement less dependent architecture.[12].Lines of Code (LOC) is the approximate number of lines in the source code.The count is based on the Intermediate Language (IL) code and this is therefore not the exact number of lines in the source code file.[12].Since the design patterns are introduction by Gamma et al. [1] in 1994, there has been an increasing consideration on the usage of the design patterns.Their research present some lines of work on the effect of patterns on code quality.Lange and Nakamura established [2] that design patterns can help as guide in program exploration and thus make the process of program understanding more efficient.However, this study was limited to a single quality attribute and to a little number of patterns.
Wydaeghe et al. [3] presented a study on the actual use of six design patterns.They discussed the effect of these patterns on reusability, modularity, flexibility, and understand ability, and the difficulty to concretely implement these patterns.They concluded that not all patterns have a positive effect on quality traits.Yet, this study was limited to the authors' own experience and it can hardly have been generalized to other contexts of development.Wendorff [4] evaluated the use of design patterns in large commercial systems and concluded that patterns do not necessarily improve their design.Indeed, a design can be over-engineered [5] and the cost of re-moving patterns is high.He did not perform a study on the impact of patterns on quality and provided only qualitative arguments.

Proposed Methodology.
The methodology for this research is divided into four steps.The first step is to identify the code bad smell form the source code of the application.The second step is to apply the refactoring techniques to the source code to remove the bad smell from the code.The third step is to apply design pattern to the source code.And the fourth and final step of this research is to evaluate the effects of this research by calculating the code metrics.
There are three hypotheses at given at this stage.The research shows that these are valid or not after conducting this research work.Hypotheses are: H1o: MI will not change significantly after applying Refactoring and Design Patterns on to the source code.
H11: MI will increase significantly after applying Refactoring and Design Patterns on to the source code.
H2o: Client code will not significantly affected after applying Refactoring and Design Patterns on to the source code.

H21: Client code will significantly affected after applying Refactoring and Design
Patterns on to the source code.
H3o: Source code reusability will not increase significantly after applying Refactoring and Design Patterns on to the source code.
H31: Source code reusability will increase significantly after applying Refactoring and Design Patterns on to the source code.

A. Formula and Equation
The formula used in this research study are:

Depth of Inheritance (DOI)
The number of class definitions that extend to the root of the class hierarchy.

Class Coupling (CC)
The Class coupling is how many classes are directly depended upon a class.

Lines of Code (LOC)
LOC is the approximate number of lines in the source code.The count is based on the Intermediate Language (IL) code and this is therefore not the exact number of lines in the source code file.

Discussion of the Results:
The results of software code metrics are represented in numeric form.These code metrics results are calculated by using visual studio 2015 community edition tool.
The table III shows the results of existing source code structure of Data Management application and code metrics of the three classes (QuestionDetailForm.cs, ExportsData-From.cs, and ImportExternalDBForm.cs).The table structure is that it contains 5 columns and 4 rows.The top row contains the headings and rest of the four contains the results of code metrics.These code metrics are the collected before applying refactoring and design patterns on to the source code.The number shows that the code is poorly structured and has less maintainability which shows that it is very difficult to maintain the source code.And that was the initial motivation to this research.The table II shows the results of the source code structure of Data Management application and code metrics of the six classes (, QuestionDetailForm.cs(A), ExportsData-From.cs(B), ImportExternalDBForm.cs (C) ParseDataHandl-er.cs(D),CSVHandler.cs (E), and BLLQuestions.cs(F)) after applying the refactoring and designs patterns.The table IV structure is that it contains 5 columns and 7 rows.The top row contains the headings and rest of the four contains the results of code metrics.

b. Code Structure and Code Metrics After applying refactoring Design patterns
There are three new classes (D, E, and F) are constructed as a result of removing the identified code bad smells and applying refactoring techniques and design patterns on the code.The MI class A is significantly decreased because of DOI is increased by applying design patterns (strategy, facad and, abstract factory) in a combination, and CCM, CC, and LOC is decreased is due to applying, duplicate code, large methods, temporary fields, feature envy, long Method, divergent changes refactoring techniques.
The MI of class B is increased 28% (from 42 to 54) which good due to decreasing in LOC 38% (from 1691 to 1060), CMM 63% (from 668 to 247) and CC 23.12 %( from147 to 113).The MI of class C is increased 25% (from 31 to 39) which good due to decreasing in LOC 38% (from 1691 to 1060), CMM 40% (from 327 to 199) and CC 24 %( from114 to 87).These significant changes in code metrics are by applying, long Method, duplicate code, temporary fields, large methods, long Method, feature envy, divergent changes refactoring techniques.
These results after applying refactoring and design patterns shows that the code structure of Data Management application is change new class (D, E, F) are added into the source code and the Maintainability index is increased for the majority of the classes code which is good for code maintainability and understandability.Cyclomatic Complexity is decrease which good for code understandability.Depth of inheritance is also decreased code coupling and LOC are also decreased that is better for cod reusability, expandability, and understandability.This research shows that the applying refactoring and design patterns in combination results on the source code has a positive impact or effect.The results justify the initially provided H11, H2o, H31 hypotheses which were given at the earlier stage of this research study.

Conclusion.
This research study is conducted to find either the code quality improves or not after applying the deign patterns and applying design patterns with thoughtfulness because they may delay the maintenance and the evaluation.The major factor in MI and the higher value of maintainability index presents that the Maintainability of the source code is easy and lower value indicated the harder to maintain the source code.Cyclomatic Complexity is the source code complexity measurement and is correlated to source code errors.The lower Cyclomatic complexity of a program tends to easier the understandability and lower the risk to modify the program.Depth of Inheritance The number of class definitions that extend to the root of the class hierarchy.It is more difficult to understand a method and fields that are defined or redefined when class hierarchies are deeper.Class Coupling the Class coupling is how many classes are directly depended upon a class.It is good to implement less dependent architecture.Lines of Code (LOC) is the approximate number of lines in the source code.The count is based on the Intermediate Language (IL) code and this is therefore not the exact number of lines in the source code file.This research results after applying refactoring and design patterns show that the Maintainability index is increased for majority of the classes code which is good for code maintainability and understandability.Cyclomatic Complexity is decrease which good for code understandability.Depth of inheritance is also decreased code coupling and LOC are also decreased that is better for cod reusability, expandability, and understandability.The hypothesis H11, H2o, H31 are satisfied.This research shows that the applying refactoring and design patterns on the source code has a positive impact or effect.

I. APPENDICES
A. Appendix A: Existing Code Metrics

Table I
represent the identified bad smell from the source code of each class and TableIIrepresent the proposed refactoring techniques and Design patterns applied on to the source code.These code bad smells are identified manually exploring the code and refactoring techniques are proposed based on the code bad smells which are identified.The QuestionDetailForm.cs and ExportDataForm.csare the god classes and have very long methods, Duplicate code and it was very difficult to manage them.

TABLE III .
a. Code Structure and Code Metrics Before applying refactoring Design patterns