I am an architect-design patterns-little story

Source: Internet
Author: User

Let's start with a story.

While the Declaration of Independence was still being drafted, Benjamin * Franklin sat by Thomas * on the side of Jefferson and told Jeffrey, "We believe these truths are holy, without a doubt, "the wording is changed to a very famous sentence now." We think these truths are self-evident ". According to Walter Isaacson, Jeffrey was furious with Franklin's changes. Franklin realized that his friend was excited and told him the story of another friend John * Thompson John Thompson.

Yu Han * Thompson has just started to work in the hat manufacturing industry and wants to design a label for his company. It is designed as shown in:

 

650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px "title =" u = 2178851506, 581098965 & fm = 52 & gp = 0 "border =" 0 "alt =" u = 2178851506, 582138965 & fm = 52 & gp = 0 "height =" 83 "src =" http://www.bkjia.com/uploads/allimg/131228/12311V141-0.jpg "/>

John Thompson, hat dealers, production and sales hats, cash payments

Before enabling the new tag, John decided to show it to a few friends and listen to their opinions. The first friend thought that the word "hat dealer" was a bit repetitive and unnecessary, because the words "Make... hat" in the back already showed that John was a hat dealer. So the word "hat dealer" was deleted. The second friend thinks that the word "make" can be avoided, because the customer will not care who made the hat. Therefore, the word "production" was also deleted. The third friend said that he thinks "cash payment" is useless because there will be no customers who buy hats on credit card. Generally, people buy them in cash. Therefore, these words are also deleted.

Now the tag becomes: "John Thompson sales hats"

"Sales hats !" Another of his friends said, "oh, no one thinks you will give him a hat. What is the use of this word ?" Therefore, "sales" was deleted. The word "hat" is obviously useless, because the logo already has a hat image. So it is eventually simplified:

650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px "title =" u = 2178851506, 581098965 & fm = 52 & gp = 0 "border =" 0 "alt =" u = 2178851506, 582138965 & fm = 52 & gp = 0 "height =" 83 "src =" http://www.bkjia.com/uploads/allimg/131228/12311V141-0.jpg "/>

John Thompson

In Simple and Direct, Jacques Barzun explains that all excellent works are constantly changed.

Up to now, you may feel that it has something to do with the design pattern, but it does not have much to do with it. Let me ask you a question: Why do you want to use the design model?

Or let me change the question: how do you understand the design model? How do you use the design pattern? In this story, we actually talk more about refactoring. In a sense, it has become a driver of the application design model. That is to say, it is not easy for us to do things well at once, in the reconstruction process, we use the design pattern to make your system better!

Must the design pattern be used in refactoring? Of course not. It's just that in our software environment, most of the time, they come along.

Q: What is the design pattern?

1. The design pattern is more like a small architecture. It follows some principles to make our code more elegant.

2. It is like a term. For example, if I talk about a policy model, you will know what I have done. If you do not understand the rule mode, I will explain that I have stripped some variable behaviors. You can enter your own defined classes to change my behavior, and this may not be enough ....

Q: When should I use the design model?

1. Any reasonable place

Q: How to Use the design mode?

Understand the design pattern and make your system meet your expectations in your refactoring process, such as decoupling and reuse. Of course, when you are skilled, you can consider adding the design model to the design system in advance. Even don't stick to the design pattern. You can change it slightly based on the actual situation and tend to the design pattern.

Now there are a lot of reference articles and even specific examples for the design pattern. In order not to repeat the wheel, I also try to find some articles that can be reproduced to help you better understand the design pattern. Similarly, I recommend you read more books. This article will mainly refer to the following books: HeadFirst design mode, reconstruction and mode, and the beauty of short codes. java and mode.

-- At the same time, it is recommended that the author watch The HeadFirst series to see the beauty of short codes and the reconstruction and mode.

This article is from the "scholar" blog, please be sure to keep this source http://yjplxq.blog.51cto.com/4081353/914401

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.