How to design architecture

xiaoxiao2021-03-06  61

How to design architectures?

Axing (Reprinted from www.linuxaid.com.cn) May 04, 2003

Part 1 layers (Layer) This concept is very unspeakable in the computer field. The computer itself reflects a layer of layer: system call layer, device drive layer, operating system layer, CPU instruction set. Each layer is responsible for your duties. The network is also the concept of the layer, the most famous OSI's seven-layer protocol. Layer is as good as the software field. why? Let's take a look at what is the benefits of using layer technology: ● You use layers, but don't need to understand the implementation details of the layer. ● Another technique can be used to change the base layer without affecting the application of the above layer. ● Depending on the dependence between different layers can be reduced. ● It is easy to develop outline standards. ● The floor under the bottom can be used to establish a number of services on the top layer. Of course, the layer also has a weak point: ● The layer is impossible to encapsulate all the functions. Once the function changes, it is necessary to wave all the layers. ● The efficiency is reduced. Of course, a problem with the hardest layers is what all layers have, and what kind of responsibility is to be taken. Typical three-layer structure three-layer structure is estimated that everyone is very familiar. That is to represent the (Domain) layer, the domain layer, and the infrastructure layer. Indicates that layer logic mainly handles interactions with users and software. Now most popular is the window graphical interface (WIMP) and HTML-based interface. The primary responsibility of the layer is to provide information to the user, and translate the user's instructions. Transfer to the business layer and the infrastructure layer. The infrastructure layer logic includes communication and other system communication, and represents the system execution task. For example, database system interactions, and interaction with other application systems. Most information systems, the biggest logic of this layer is to store lasting data. Another one is the domain layer logic, sometimes called business logic. It includes calculations for input and storage data. Verify the data indicating the layer, assign an infrastructure layer logic according to the instruction of the representation layer. In the field logic, people always don't know what is logical, what is other logic. For example, there is such a logic in a sales system: if the sales volume of this month increases by 10% from the previous month, it is necessary to use a red tag. To implement this feature, you may put logic in a representation layer, compare two months, if it exceeds 10%, marked as red. Doing this, you put the domain logic in the representation layer. To separate these two layers, you should now provide a method in the domain layer to compare the growth of sales. This method compares two months of numbers and returns the Boolean type. The layer is a simple call, if True is returned, it is marked red. Example layer technology does not have eternal skills. How to use the specific situation can be determined, and I will list three examples: Example 1: An e-commerce system. Requirements can be able to handle a large number of users, the user's scope is all over the world, and the numbers are still growing. However, domain logic is simple, nothing more than orders, and connecting parts of the inventory system. This requires us 1, indicating that the layer is friendly, can adapt the most extensive users, so HTML technology; 2, support distributed processing, with a thousands of accessories; 3. Consider the future upgrade. Example 2: A rental system. There are fewer users of the system, but the domain logic is very complicated. This requires us to make a very complex system of domain logic, in addition, it is necessary to provide them with a convenient input interface. This way, WIMP is a good choice. Example 3: Simple system. Very simple, less users, less logic. But nor is it no problem, simply means to be delivered quickly, and you must fully consider the future upgrade.

Because the demand is increasing. When three examples of layering, we need to solve problems in general theory, but should make specific solutions for problems. These three examples are more typical. In the second example, it may be necessary to be strictly divided into three levels, and there may be additional intermediating layers. Example 3 does not need, if you want to see data, only a few Server pages can be placed all logic. I usually separate the representation layer and the domain layer / infrastructure layer. Unless the domain layer / infrastructure layer is very simple, I can use tools to easily bind these layers. The best example of this two-layer architecture is to build a system based on the Windows interface based on the SQL database in the VB, PB environment. Such a representation layer and the infrastructure layer are very consistent, but once verification and calculations become complicated, this approach has congenital defects. Many times, the domain layer and infrastructure layers look very similar, this time, it can be placed together. However, when the business logic of the domain layer is different from the organization of the infrastructure layer, you need to separate both. More layers of layer patterns are most common, especially for IS systems. Other architectures are also available, but it does not apply to any situation. The first is Brown Model [Brown et al]. It has five layers: representation, control / intermediar / mediator, domain layer (DOMAIN), Data mapping, and data source layer (DATA SOURCE). It is actually an increase in two intermediate layers in the three-layer architecture. The control / intermediary layer is located between the representation layer and the domain layer, and the data mapping layer is located between the domain layer and the infrastructure layer. Represents the intermediard layer of layers and domain layers, we are generally referred to as the field intermediary layer, is a commonly used layered method, usually for some non-visual controls. For example, for a particular representation layer tissue information format, navigating between different windows, processing the transaction boundary, providing the server's FACADE interface (see design mode). The biggest danger is that some domain logic is placed in this layer, affecting other representations. I often find that the behavior is allocated to the representation layer is good. This simplifies the problem. However, it indicates that the layer model is more complicated, so these behaviors are placed in non-visualized objects and extracting a representation - the domain intermediary layer is still worth it. BROWN ISA represents a layer of lamination layer Control / intermediary layer representation - the domain intermediary field layer field layer data mapping layer database interactive Database Mapper data source layer infrastructure layer layer layer and infrastructure between the fields are in this book The mentioned Database Mapper mode is one of the three domain layers to data connection. And expressing the field intermediary layer, sometimes useful, but not every time it is useful. There is also a good layered architecture is an architecture of J2EE. This discussion can be seen in "J2EE Core Model" book. His layered is a client layer, a presentation, a business, an Integration, a resource layer (Resource).

The difference is shown below: The J2EE Core ISA Customer Layer is running on the client representing the layer of representative layer running on the server. Layer business layer field layer integrated layer infrastructure layer resource layer infrastructure layer communication external data Microsoft's DNA architecture defines three A layer: representation, business layer (Business), Data Access, which is similar to my architecture, but there is also a big difference in the delivery mode of the data. In Microsoft's DNA, the operations of each layer are based on the SQL query result set of data stored. In this way, it is actually an increase in coupling between the layer and the service layer with the data storage layer. DNA's record set is similar to the Data Transfer Object. Part 2 organizational domain logic should organize layer-based systems, and the primary is how to organize domain logic. There are several modes of the domain logic. But the most important thing is the two methods: TransArtion Script and Domain Model. One of the selected is selected, and others are easily determined. However, there is no obvious boundary between these both. So how to choose is also a university. In general, we believe that the domain logic is complicated in a system of domain model. The TransAtion Script is a handler that represents a layer user input. Including verification and calculation, storage, calling other systems, and transfer data back to the representation layer. One action of the user represents a program, which can be Script, or also a trigger, or several subroutines. In Example 1, the test, add a book in the shopping cart, display the delivery state, can be a TransAtion Script. Domain Model is the model to establish a corresponding domain noun, such as books, shopping carts, etc. in Example 1. Test, calculation and other processing are placed in the domain model. The TransAtion Script belongs to structural thinking, and Domain Model belongs to OO thinking. Domain Model is more difficult to use, once habits, you can organize more complex logic, your thoughts will be more o. At that time, even a small system, you will naturally use Domain Model. But how do you choose? If the logic is complex, then use Domain Model: If you only need to access the database, the Transization Script will be better. But the demand is constantly evolving, and you can make it easy to ensure that future needs will be so simple. If your team is not good at using Domain Model, then you need to weigh the output ratio. In addition, even the TransAtion Script can also be separated by logic and infrastructure, you can use Gateway. For example, there is no doubt that Domain Model is used. For example, it is necessary to trade. For Example 3, it is difficult to say that it will not be like Example 2 in the future, you can now use TransAtion Script, but you may have to use Domain Model in the future. Therefore, the decision of the architecture is critical. In addition to these two modes, there are other moderate modes. Use copy controller is between the two. Only business logic related to a single use case is placed in the object. So roughly they are still using TransAtion Script, and Domain Model is just a collection of Database Gateway. I don't use this model. Table module is another moderate mode. Many GUI environments rely on the return result of the SQL query. You can build objects in memory to separate the GUI and databases.

For each table, each line needs a keyword variable to identify each instance. Table Module Suitable for many components to build on a universal relational database and is less complicated by the domain logic. Microsoft COM environments, as well as its .NET environment with ADO.NET is suitable for this mode. And for Java, it is not suitable. One problem in the domain logic is that the domain object is very bloated. Because the behavior of the object is too much, the class is too big. It must be a supercoming. This is to consider which behaviors are generic, which are not, can be processed by other classes, possibly the use case controller, or it may be a layer. There is also a problem, replication. He will lead to complex and inconsistent. This is greater than the bloated harm. Therefore, I would rather be bloated, and don't copy it. Wait until the bloated is harmful to deal with it. Choose a local run domain logic Our energy is concentrated on the logical layer. Domain logic either run on a client or run on Server. A relatively simple approach is to all concentrate on the Server. This way you need to use HTML front and web server. The benefits of doing this are that upgrades and maintenance are very simple. You don't have to consider the synchronization problem of desktop platforms and Server, and you don't have to consider compatibility with other software of your desktop platform. Running in the Client Suitable for a rapid response and no network. On the logic of the Server, a smaller request for the user, as well as information is required from Client to Server winding. The speed of the reaction is inevitable. Besides, the coverage of the network is not to say 100%. What is it for all layers? Infrastructure layers: generally in Server, but sometimes copy data to a suitable high-performance desktop, but this is to consider synchronization problems. Indicates where the layer operates depends on the design of the user interface. A Windows interface can only run in the client. And a web interface is running in Server. There are also special examples, running web server on the desktop, such as X Server. But this situation is much less. In Example 1, there is no more choice, can only be selected in the Server terminal. Therefore, every bit of your BIT will around a large circle. In order to improve efficiency, try to use some pure HTML scripts. The reason for people choose the Windows interface is mainly to implement some very complex tasks that require a suitable application, and the Web GUI cannot be competent. This is the practice of Example 2. However, people should gradually adapt to the Web GUI, and the functionality of Web GUI will become more powerful. The rest is domain logic. You can put all in Server, or you can put it in the client, or on both sides. If it is in the Client side, you can consider all logic in the Client side, so that at least all logic is in one place. To move the web server to the client, it can solve the problem without the networked, but there is no more help to the reaction time. You can also separate the logic and representation layers. Of course, you need an additional upgrade and maintenance. It is not a good way to do logic in Client and Server. But for those situations that only some domain logic are applicable. There is a tip that puts the logical encapsulation of those and other parts of the system. Some field logic on your server has some field logic, to communicate with Client, what kind of interface do you have? Either an HTTP interface or an OO interface. The HTTP interface is suitable for web browser, that is, you have to choose an HTML representation layer. Recent new technologies are Web Service, communicating based on HTTP, especially XML.

XML has a few benefits: large traffic, good structure, just a loop. This is small in the overhead of the remote call. At the same time, XML is still a standard, support platform heterogeneous. XML is based on text, and can pass through the firewall. Although XML has so much benefits, but an OO interface still has its value. The interface of HHTP is not obvious, and it is not easy to see how the data is handled. The method of OO interface has variables and names, easy to see the process of processing. Of course, it cannot pass the firewall, but can provide control of security and transaction. The best is to take the director of the two. The OO interface is under, the HTTP interface is on. But doing so will make the implementation mechanism is very complicated. Part 3 organizes many people using HTML in WEB Server, and does not really understand the advantages of this approach. We have a variety of easy-to-use tools, but they have made it difficult to maintain. The way to organize programs on Web Server can be roughly divided into two types: scripts and server page. The script mode is a program, with functions, and methods to handle HTTP calls. For example, CGI scripts and java servlets. It doesn't have any two and ordinary procedures. It gets data from the HTML string form from the web page, sometimes doing some expressions, which is the reason for Perl to become a common language for CGI scripts. Java Servelet is to leave this analysis to the programmer, but it allows the programmer to access the information through the keyword interface, so there will be fewer expressions. This format of Web Server output is another HTML STRING called Response, which can be operated by streaming data. Worse, flow data is very troublesome, therefore results in the generation of Server Page, such as PHP, ASP, JSP. Server Page is suitable for responding to the response. For example, "the details of the song", but your decision depends on the input, it will be more messy. For example, "Different and rock display formats are different". Foots are good at handling user interactions, Server Page is good at processing formatting response information. Therefore, it is natural to use the interaction of the script processing request and the formatted format of the SERVER PAGE process. This is actually the processing of View / Controller in the famous MVC View Controller mode. The MVC workflow of the Web Server end is a primary point for the model of Model View Controller mode that the model must be completely separated from the web service. Use the Transaction Script or Domain Model mode to encapsulate the process. Next, we will classify the remaining mode into two types: it belongs to the Controller mode, and the mode belonging to the View. VIEW Mode VIEW has three modes: Transform View, Template View, and Two Step View. The process of TRANSFORM View and Template View is only one step, and the domain data is converted to HTML. Two Step View To process two steps, the first step is converted into a logical representation in the first step, and the second step is converted to HTML. The advantage of two-step processing is to focus on the logic. If there is only one step, you need to modify each screen when the change occurs. But this requires you have a good logical screen structure. If a web application has a lot of front-end users, two steps are particularly useful. For example, the air booking system. Different logical screens can be obtained using different second steps.

转载请注明原文地址:https://www.9cbs.com/read-90773.html

New Post(0)