. NET Beginner Architecture Design Guide (iii) design pattern

Source: Internet
Author: User
Tags object model

In the previous article, we had an initial understanding of OO design, and the most unique part of OO design was the way he looked at requirements. In this way, we don't have to rush to determine which processes the software needs to implement, what features to design, what to create, and what to look at more fundamental concepts in the requirements. First, some parts are developed according to these concepts, and then the parts are assembled to achieve the required functions. In this way, we do not need to start to know all the business requirements, just need to know some of the more important requirements, you can start to develop. This developed program can not only achieve the current needs, but also a business development platform, on this platform can continue to develop new features.

There are many practical examples of this design idea, such as Microsoft Office. The following diagram shows some of the most basic objects in Excel:

Excel's various functions are based on this object model. For example, to achieve the ability to set the font, you can write: first open a Font dialog box, the user select font, font size, and then set the font to the region:

Font font = CommonFontDialog.ChooseFont();
Application.ActiveWorkbook.ActiveSheet.Range("A1").Font = font;

Excel also exposes these object references to the scripting engine, so we can use VBA to invoke them to achieve the various functions we want, which is Office macros. We can write a VB script, copy the mouse selected area of the cell to another worksheet, and then assign the value of a cell to a formula to calculate the value we need. Excel is not only a handy tabulation tool, but also a powerful and easy-to-use development platform. Users can develop the functions they need at any time according to their own ideas. Some large software systems have such characteristics, the beginning of the clear that all the functional requirements are not possible, it is important to form a business development platform, providing some business programming interface, on this platform can continue to develop new functions. Such a development approach is difficult to implement without using OO design.

The first maintainer and first user of the software is the developer himself, so the development is rapid, flexible, and easy to maintain-features that are often available at the same time in well-designed software.

This is a difficult time to design a program using OO methods: We have found some vague concepts from the requirements, but how can we build a reasonable object model based on these concepts, which concepts should be a class, what concepts should be a method and attribute, and what kind of relationship should be between these classes? To solve this problem, the most fundamental way is, of course, to understand the need as much as possible (such as the accounting principle, to see how receivables are not collected and collected when should be accounted for, one of the principles of accounting may be an important object; Help users to do a power plan, draw a sketch, or a calculation The formula is an important object). After solving a difficult one, someone summed up the experience, formed a number of fixed routines to solve specific problems, such routines are design patterns.

Some design patterns are not necessarily related to OO, such as hierarchical mode or message mode. But most design patterns are created in oo design, and these patterns can help us discover the relationships between objects and design objects in the system. Understanding these patterns can help us to design the software more rationally. And, in the process of exploring the demand, we can also get some inspiration from the model, get the design inspiration, discover the real face of the demand.

In the last article we saw the "cost" of this type: Fee, in fact, this is a simple design pattern: Combination mode (composite). The structure of this class is as follows:

The fee type is an aggregation of his own, and you can use the GetChildren method to obtain additional charges that are included in a fee. If a fee does not include other expenses, his amount is determined by himself, otherwise it is determined by the sum of the expenses he contains, both of which are the same way for the outside world: GetValue. In this way, when we want to show a billing fee, it's much simpler to call it a day without having to judge if he has any other expenses. The combination pattern is a good representation of the level of billing costs involved.

In just the case, the aggregation class and the element class are the same type. There are also some situations where they belong to different types respectively. For example, a business, his marketing network is composed of the following elements: Companies, marketing department, direct sales shop, agents, free agents, salespersons. As in the following scenario:

The company established a number of marketing departments in accordance with the administrative Region, the marketing department established its own direct sales shop, but also with many agents and independent agents to cooperate, direct sales shops and agents hired salespersons. Every day the company needs to query and analyze the situation of each sales network, need to know how many orders they have set, how much they have received, and how many new customers they have developed.

This is a more complex structural relationship, the network type is more, their sales methods vary greatly, various types of data statistics are also different ways. And in the statistics of some values, we need to add up the number of subordinate outlets, plus the number of their own. This problem can be solved if the combination mode is used.

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.