Supporting Automatic code Review Via Design Pattern
Jiantao He, Linzhang Wang, Jianhua Zhao
State Key Lab of Novel Software Technology
Dept. of Computer Science and Technology
Nanjing University
Nanjing, China
{lzwang,Zhaojh}@nju.edu.cn
Abstract—Code review is a very important means to
ensure the quality of code in practice. It has been widely used
in industry since it was proposed. Nowadays code review is
still mainly done by manual work in industry. However,
increasing scale of the software challenges manual reviewing.
So automating the code review process is highly desired.
Design patterns are a set of summaries of code design
experiences that are widely used repeatedly, and well classified.
Programmers need to correctly implement code based on
design patterns. To ensure that the code is implemented as
expected, this paper proposes an approach to automatically
review code in the view of specified design patterns. Firstly,
we identify the design patterns that are specified in the design
models. Second, we construct a set of review rules by
extracting design constraints from identified design patterns.
Last, the code is checked against the generated review rules,
and inconsistencies are reported as result. A supporting tool
was developed, and two experiments were conducted to
demonstrate the applicability of our approach.
Keywords
:
Code Review, Design pattern, UML, Abstract
Syntax Tree
I. INTRODUCTION
Peer review is one of the success practices to ensure
software quality in software industry in addition to software
testing, analysis. It aims to find the potential defects in
different software development phases. In the requirements
analysis phase, review can find the indefinite or incorrect
specification, and find the defects in requirements in time can
reduce the overhead of repeated modification in later phases,
ensure that all the requirements defined in the requirements
specification are suitable; in the design phase, review can
evaluate the suitability of preliminary design, that is described
in software design specification, in the aspect of overall
structure, external interfaces, the main components function
assignment, the global data structures, and the interface
between the main components and so on. In coding phase,
code review method checks the consistency between code and
design, situation of the code execution standard, correctness of
the code logic expression, rationality of the code structure and
the code readability. It can find the problem of implementation,
such as the inconsistency between code and design, the
maintenance problem, the completion of code (whether all the
requirements are implemented), and the code correctness and
so on. Code review can produce higher-quality code in the
coding phase, it can find the inconsistency and completion
defects which testing can’t, and the overhead will be much
smaller if we find and repair the defects in coding phase other
than testing phase.
Design patterns are general reusable solutions to commonly
occurring problems within a given context in object-oriented
software design and typically show relationships and
interactions between classes or objects. Since the earliest
concept of design pattern is proposed, it has been widely
accepted and applied in academia and industry to describe the
design vision. As a representation of design vision, design
patterns are widely used, especially in object-oriented
community. We can find that the percentages of classes that
involved in design patterns in different projects are from 47%
to 74%. To our knowledge, nowadays, software engineers still
manually implement the software design into the code when
they understand the software design vision, i.e., design
patterns. Thus, it is possible to introduce human errors in code,
such that the code does not conform to the design patterns.
And code review is generally the most common method
for enhancing the quality of software during the
implementation phase. It is an efficient solution to find defects
in the artifact during the development life cycle. However, as
the complexity and size of software systems grow, manual
code review is labor-intensive and error-prone. In addition,
design patterns are seldom considered in code review activities.
In this paper, we propose an approach to automatically
review code in the view of specified design patterns. Firstly,
we identify the design patterns that are specified in the design
models. Second, we construct a set of review rules by
extracting design constraints from identified design patterns.
Last, the code is checked against the generated review rules,
and inconsistencies are reported as result. We aim to provide a
supporting tool to help programmer find the inconsistency
between code and design (design patterns).
The rest of the paper is organized as follows. In section 2,
we introduce code review and design pattern. Section 3
presents our approach for automatically reviewing the code
based on the design patterns. Section 4 presents 2 case studies
and evaluations of our approach. Section 5 reviews the related
work. Finally, section 6 concludes the paper and discusses
future work.