What is design pattern? When talking about design pattern, many people talk about architectural design, because they all look at the interpretation of the classic book "design patterns" of the four-person group. If they don't digest it, they simply accept it. If you cannot explain design pattern in a more practical way, I doubt whether they really understand the true meaning of design pattern.
What is pattern?
The simplest definition of pattern is: as long as it is repeated, It is pattern. According to this definition, we can find a bunch of pattern examples in our life:
Pattern in the fourth advertisement:
The original price..., now purchase as long as..., also send you a group of..., please immediately call..., such as busy line please dial later.
Use the split screen to show the difference before use to strengthen the persuasiveness. For example, upgrade from C to E (Note: C and E are not programming languages ).
Find someone to say: "Jerry! Thank you for introducing this set of OLE Lee Java series. In just three months, I became the top Java expert in the company. This is amazing !」
Pattern during election:
1. Questioning a's money or extramarital affair
2. Drag your family to the station and cry for an emergency.
3. Sing "love fight will win 」
Other techniques, such as the golden party, have repeated features, so they can be regarded as pattern.
Pattern in a movie
There are also a lot of pattern in the movie. Please refer to the example below.
Improve the pattern of the degree of tension during hunting
When the bad guys sought after good people, they hid in the car, but found that the car could not move, and the engine gritted. while trying to continue, they read the word "Come on, come one 」.
When the bad guys are chasing good people, they rush into the elevator and press the close button to blurt out "Come on, come one 」.
Many movies use the two pattern mentioned above. Although it is an old pattern, every time I see the pattern, it always makes me nervous and almost suffers a heart attack. I have to admit that these two pattern are really effective.
Increase the rationality of leading role killing bad guys.
In the final part of the movie, the bad guys fight with the NPC and finally win the good guys. But if the good guys directly slaughter the bad guys, their images will be damaged in the hearts of the audience, but the bad guys are broken into the bones, secretly taking out a gun to target the good guys, saying that the time was so late, the good guys suddenly noticed that in order to protect themselves, they shot the bad guys. This pattern allows good people to be human, and the bad guys to die.
Pattern of bedplay
Whether it is related to the story or not, the scriptwriter and the Director always love to add a piece of bed drama with passion. This pattern is quite confusing for me and my family, because every time we see this, our conservative family often feels embarrassed. The pattern we reflect is: Excuse me to pour tea and go to the toilet, call... and stay away from the limelight... but the eyes are still scanning from time to time.
Terrorism Pattern
I don't need to give an example. The first episode of the movie Scream analyzes a lot of pattern for the horror film.
Formula
There are many pattern movies in Hollywood, but few in Europe. As for the films produced by Quentin Tarantino, pattern is hard to find. Because Hollywood movies can easily find pattern, they often have similar feelings. Many people criticize Hollywood movies for being "public 」.
Basically, pattern is a formula. So is formula a good thing?
In art, the results of the formula will become rigid, so the negative effects are mostly. The film is known as the "Eighth art" and also an artistic creation. Therefore, it is best not to have too many pattern. Otherwise, it must be criticized by the film critics for "no new ideas 」.
In terms of engineering, it is a good thing to formula. These formulas are all the results of continuous engineering. Using these formulas can ensure that the project has a certain quality and speed up the project. Software development is also a project, and formulas should be used as much as possible. (The software also requires an artistic side, which is not covered in this article ).
What is design pattern?
Therefore, pattern is a kind of intelligent crystallization of "endless efforts. The difference between experienced experts and inexperienced beginners is that experienced experts know how to apply certain formulas (pattern) at the right time to solve specific problems, this is the know-how developed by experts over years (see the article "knowledge economy in the software industry ).
Generally, object-oriented software development programs can be roughly divided into OOA (object-oriented analysis), OOD (object-oriented design), and OOP (object-oriented implementation ). The pattern used in the object-oriented design stage is called design pattern. Using a good design pattern can make the system architecture better (and faster), which will be of great help for subsequent Oop, testing, and maintenance. Design Pattern will tell you when delegation is used instead of inheritance, and when interfaces are used instead of class... and so on. These are the smart crystallization of the software industry's predecessors.
I want to emphasize that design pattern refers to the pattern in the design period. But the pattern in coding (such as program code contraction) should not be called pattern to avoid confusion. The pattern of the coding period is best known as the coding style (or code style ).
The design pattern term can also be used in many places. I think Sun Tzu's Art of War is a book designed pattern in the military field, which tells you when to adopt what military actions. As for how to hack people, it is part of implementation and not part of Sun Tzu's Art of War.
What is anti-pattern?
Not all pattern values are good. A bad pattern is called anti-pattern. If your system contains anti-pattern, it indicates that you have made "Common Mistakes 」. In short, anti-pattern is an example of an error and should be avoided as much as possible.
Make design pattern your demand
Many people sigh at the design stage: "pattern is used to hate less .」 In fact, you can avoid this situation. There are many design pattern and anti-pattern books on the market. As long as you read these books and understand the true meaning of each pattern, you can surge in skill in a short period of time. Even if you have read the design pattern, you may forget it after a while. So it is best to take out the design pattern book for review in a short time.