Reconstruction-Agility-ID card number reconstruction Review

Source: Internet
Author: User
ArticleDirectory
    • Let the bullet fly
    • Iteration 1:
    • Iteration 2:
    • Iteration 3:
    • Iteration 4:
    • Since then, XX and XX have lived a happy life ......
Looking for reconstruction cases

Reconstruction cases are difficult to choose. Of course there are many reconstruction cases in our actual projects, but they are not suitable for being elaborated in the article. It is not because of confidentiality, but because the content of the business itself is too complicated. Of course, this complexity is relative. For a short article, I am afraid that the business logic is the smallest part, and the capacity is insufficient. In addition, too much elaboration of business logic leads to overwhelming competition and masks the attention of reconstruction. Therefore, to select something that everyone is familiar with, the ID card number exactly meets my first requirement.

As a matter of fact, it is necessary to have an original version and complete the actual functions. Open-source ChineseCodeSharing also provides me with a resource library. Code sharing is an ideal platform, and the code size is not large. Every sharing has a clear purpose function.
It looks like a gold mine. However, with the in-depth search and view, there are few that can enter my target range. Most of the Code is just a binder that combines the calls of external libraries to complete a task. Some code, the method is too large, while the code is simple and repetitive. It seems necessary to refactor, but it does not show the different aspects of refactoring, and there are also the problems mentioned above, is the adhesive code block.
(Copyright: 2012-2013 Yu qin'an)

When I saw the three characters of my ID card, my eyes lit up. The seemingly simple identity signs included too much content:

    1. It is a value object in a typical business domain (not to be confused with the value object in the C # syntax concept). In our own system, we also have the idea of creating an ID card number value object. We have previously made a month object (yearmonth), which is very easy to use. However, it is not suitable for short cases because of its many functions and large amount of code.
    2. It does not depend on external libraries. Not to mention, I can only refactor this independent code, but it is limited to space and highlights.
    3. Its business logic is very popular. Who has no ID card?
    4. The sharing code has incorporated enough business logic. What I do is to keep this unchanged and focus on refactoring. A perfect reconstruction case.
Agile reconstruction and Composition Let the bullet fly

I set a goal. When I started, my mind was full of ideas. The original code is Java and needs to be changed to C #; getxx can be used in attribute mode, which is simpler; since it is a value object, it seems that it is more appropriate to use struct than to use glass; As value, it should be an immutable class, so it should not be resolved dynamically in the constructor, it is more appropriate; The implementation of validation is not suitable ......
Yes, Senior agile practitioners like me still have this impulse in the first place, and too many ideas will be implemented immediately. This is actually a kind of human nature. It doesn't matter. I just let the bullet of thinking fly for a while.
The first thing I think of is the completion test. Speaking of testing, I have used mspec for many times to get started with mspec, but I have never been able to write it down. I have already written many blog posts that use mspec directly, you can learn machine in actual use cases. specification.
It is a supplemental test. In fact, many modifications have been made to the Code Editor errors from Java to C. Testing is completely missing from the original code. Adding this is part of refactoring.

Iteration 1:

A lot of preparation work has been done. At the end of the test, only one getaddress () is written (). This became my first day. The first test became my first day goal. Around this goal, I gave up all work that had nothing to do with it, especially the content of the previous bullet.

Iteration 2:

The next day, the things to be done were very clear at once, and other functional tests were completed step by step: Birthday, gender, and so on. It's almost impossible to use your mind. Sometimes, this is the case. There are waves, calm waves, and only tests are the ship's rudder.
According to the number of tests, the next day is very fast. The written content is also rich.

Iteration 3:

The progress on the third day was much smoother. Test all functions, such as birthday, gender, and verification. There is an episode where the verification logic is extracted into an independent class. To sum up, there is nothing to say, but the reconstruction itself has a look.

Iteration 4:

On the fourth day, I started to do what I wanted to do, sort out the logic, and clean up the code. With the help of the code coverage tool dotcover, the complexity analysis of vs verifies the reconstruction effect from the other side. In fact, we should also analyze the code before refactoring, and compare the two phases, the effect will be much better.

Since then, XX and XX have lived a happy life ......

My blog is over, but as code improvement, it is not over. Some of my initial ideas have not been completed yet, such as struct. I also lost some services, such as converting a 15-digit number to 18-digit number. This is sufficient for the presentation of refactoring. Most importantly, I have created a robust <Test-implementation> pair, on which you can continue to improve.

The Code itself does not have a lot of technical content, but the refactoring process, task subdivision, and the concept of small step forward are fully expressed. As an experience, it would be totally different if you could follow the process I 've taken and go through it. Agility is practice, and reconstruction is practice. Only practice can experience practice.

(The Copyright in this article is 2012-2013 Yu Qinan | repost the article to indicate the author and source)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.