Design Pattern learning-why should we adopt design patterns?

Source: Internet
Author: User

Today, software development has changed dramatically. A major change is the introduction of structured programming. Structured Programming divides applications into many functions,
Each function executes a specific task, and each function is named for what it will execute, followed by object-oriented programming. Make C ++ and smalltalk
Nowadays, developers rely on classes to write their code and use these classes modeled in reality for programming.

The main objective of these methods is to help communication within or across teams. "How did a customer open an account ?" Make one developer and the other
It is very easy for developers to communicate with end users. Then use the class to model.

In recent years, the developer community has seen the rise of "Design Patterns". The design patterns are about communication, which helps developers better understand and understand
Clearly describe the code given.

Design Mode and communication

Imagine two carpenter who are discussing how to connect to use a set of drawers. One person asks, "in what order are you going to connect these drawers"
The other replied, "I want to take two pieces of wood, cut it down by about 2 cm, angle it at 45 cm depth, cut it at forty-five depth by 4 cm, and then
And then ......"

The second person wants to describe how to perform the final engagement. It is a standard method of engagement in woodworking. Such a description is not a target communication, but is actually hidden.
Communication: If the second person says "I want to use a ytail joint", more information will be transmitted.

In the second example, woodworking is describing a normal connection method and based on their understanding. For example, every complex combination,
The intensity of integration.

This is the case of a design-mode application in software development. If a developer says "I am using a policy mode" or "I am using a factory mode"
To another developer who understands this mode and knows how to use it.

What is mode?

Instead of describing the code, the pattern allows developers to solve the problem by communicating with each other. The pattern is for a general design
A reusable solution to the problem.

For many modes, the description of a UML diagram may not be clear about all the modes. For example, the agent mode and the Decorator Mode Share a UML
Images, but they are essentially different. This is one of the key concepts of our learning model. This is why and when a specific situation should
Applied.

Naming is also very important. Many people call the code that creates some things as a factory. However, not every creator is a factory.
The correct message actually has two different factory models: factory methods and abstract factory methods. Different models and understandings are not all created.
All are called factories, which helps developers to communicate with each other by using the model name.

Design Specifications

A good OO design must follow certain specifications and use modes to support these specifications. For example, a more flexible developer is allowed to perform interface-oriented programming, rather
The "interface" mentioned here is not only an interface keyword, but also an abstract class. Many design patterns follow the "On/Off" rule to expand
Scalability. Therefore, when the tested code should not be changed, the new code should be excluded. For example, the rule mode allows the runtime Time Code
Provided, the. net Array. sort class is such an example. The sorting rule cannot be physically modified, but you can provide it with a rule to compare items.
Therefore, the code is closed for modification, but it can be extended to compare different types of entities.

Application Mode in. net

Many documents are compiled around specific readers. Java developers, Java and. NET are very similar. Developers often transplant the application design patterns in Java
C # Or VB.net, however, Java and.. NET is not the same environment, even if they have the same roots, such. net has a proxy, Java does not ,. net (at least in C #) has anonymous
Methods, but Java does not. These technologies can be applied to many design patterns, so that the modes written in C # and Java are basically different. Understanding the features of C # is accurate.
The key to using the design pattern in. net.

Using. NET features to change the way we use some common patterns, for example, using a proxy to implement the observer mode, using the combination of the state mode and the partial class will allow
We put the code into multiple files. Each State uses a file to contain a class, making it easier to manage the code. Using threadstatic means that the thread is bound to the single-piece mode.
It will be easier to create. Other technologies that can be used in design patterns include. Net iterators and transparent proxies.

Summary

The mode provides a mechanism between developers to allow developers to communicate at a higher level, rather than at the code level, and aims to understand the developed code.
The pattern can be applied to the environment where it is applied. It can exploit many. NET features, such as delegation, partial class, and anonymous method.

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.