1: About multilayer architectures (N-tier)
A multi-tier architecture is an industry-proven software architecture model that is quite resilient to developing enterprise (client/server) application support for scalability, security, and fault tolerance. But in. NET world, we have many tools and products, but no instruction manual is about how to design and implement a good multilayer architecture model, such as some sample version, demo, and so on, we may have heard, see some of the multi-layered architecture model of the use and benefits, but more know how to use and implementation, Not too much to think about, why are we designing this? What are the design patterns that this design conforms to? What are the design principles to follow? or understand the concept of a bit of multi-layered, or even simply do not understand the definition. So the main thrust of this article is to create a "multi-layered architecture" that introduces concepts, advantages and disadvantages, differences with other architectures, usage scenarios, and so on. But, overall, this is one of the best solutions for a software architecture.
2: noun introductionphysical layers and processes (tier and process)in English, there is the meaning of the presentation layer, simply speaking--the physical layer and the logical layer. It is said that the layer is cut horizontally, and the tier is cut vertically, and this is defined only from the angle of observation. Tier typically means a physically deployed computer that can run a service on a single tier. Layer means a logical combination of components with similar software functions, layer is designed to be better developed and better organized. Strictly defined,tier is this: client->web Server--Application server--database, that's all. If you want more tiers, you can only expand the application server and divide the application server into tiers. More often, a tier can host multiple layers, and a layer can be distributed across multiple tiers, such as the layer that provides the underlying public service, which is the case for rich client applications. at the same time, the layer also implies that "the following layer is generally to provide services for the layer above", then the logic layer to express is more appropriate, and tier this aspect of the hint is relatively weak, with the physical layer to express also appropriate. Figure 1: As we can see in Figure 1, the persistence layer (persistence layer) consists of two parts: the Persistent Operation Class library (persistence Lib) and the WCF Data service. The persistent operation type typically runs the same process in the persistence layer and combines WCF Data Services as the provider of the business tier, while WCF Data Services can run separately on a single physical layer. Another example is that we may extract data validation from the business layer as a standalone class library (at this point in the logical definition, data validation is also in the business layer) in order to provide better interaction performance for the customer presentation layer invocation. In that case, the data validation class library runs in the same process as the customer presentation layer, while the rest of the business layer runs on a separate physical layer.physical layers and processes (tier and process)Typically, a logical layer runs a process and runs on a separate computer at the same time. Two different logical tiers can be run independently in two different processes, and the processes communicate with one another. However, if the IPC situation is not based on distributed, then the two processes will be shared memory space, then the processing of different processes should be placed on a computer, then a physical layer corresponds to two processes, equivalent to two logical layerslogical layers and processes (layer and process)Typically, a logical layer runs in a separate process, with multiple logical tiers running in a separate process, and a logical layer running multiple processes. Can be divided into different kinds of situations3: Three-tier architectureFirst, the next three-tier architecture is introduced, and layer three is a typical example of a multilayer architecture. Includes: The presentation layer, the application layer, the data layer, the order is inherited from the top level to the bottom.Presentation layer: the level at which users can access and interact directly, such as the Desktop UI, page pages, and so on, can also be called as clients. Application layer (Application layer): This layer encapsulates the business logic (in simple terms, rules and data validation of business operations), domain concepts, data access logic, and so on, which can also be called the middle tier Data layer: An external data source used to access application data, such as database services, CRM systems, ERP systems, hosts or other legacy systems, etc. One of our common is database services, in a multilayer architecture, we need to use non-embedded data service systems, such as SQL SERVICE,ORACLE,DB2, MySQL or Postgrasql. A non-embedded database service can run on a standalone computer, and an embedded database service, such as ACCESS,DB on a standalone computer, cannot be used in a three-tier architecture. 4:1-tier,2-tier,3-tier or More-tier architecture1-tier: All the logical tiers run on a single computer, in order to implement the 1-tier architecture, we need to use a check-in type of database system, and cannot run in a separate process, instead, those at least 2-tier because non-embedded databases can typically run on separate computers. 2-tier: The presentation layer and the application tier, one of which runs on a single computer, or the application and data tiers, one of which runs on a single computer, with no more than two computers across the application. 3-tier: Is the most typical one in a multi-layered architecture. Each layer in layer three can be run separately on separate computers, but can also be deployed on the same computer (the most common of which is the three-tier architecture, but eventually deployed as a Taichung). N-tier:3 or more layer architectures. Figure 3 depicts an n-tier architecture. Some three-layer types can be further segmented into multi-layered architectures. For example, the application layer can be further divided into the business layer and the persistence layer, the presentation layer can be further divided into the client layer and the client presentation layer. Of course, all of these logical layers can be deployed on the same computer. Client layer: This layer is directly interacting with the user, there may be several different types of coexistence, such as the WPF window, the HTML page, and so on the client presentation layer: Contains the performance logic required by the customer. An IIS server, such as ASP. NET MVC, also adapts to the business layer business layer of different customers: all the domains and logic involved in processing and encapsulating the business, also known as the domain layer persistence layer: processing and reading or writing to the data layer of the business data, or the data Access Layer data layer: External data sources such as databasesWhat is the difference between 5:n-tier and MVC architecture?The MVC pattern (model-view-controller) isa software architecture model in software engineering that divides a software system into three basic parts: model, view, and controller. 1. Controller-Responsible for forwarding the request, processing the request. 2. View-Interface designer for graphical interface design. 3. Model-programmer-programmed functions (implementation algorithms, etc.), database experts for data Management and database design (can achieve specific functions). Take the most typical three layers of a multi-tier architecture, in the three layer, the data Access Layer (DAL), the Business Logic layer (BLL), the web layer, the purpose is separation of duties. MVC is Model-view-controller. Strictly speaking, these three add up is the three-tier architecture of the Web layer, in other words, MVC is the expression layer again differentiated, divided into the controller, view, entity three parts. The view completes the page logic, and the model encapsulates the data that needs to be passed to the view for display, while the control layer communicates with the BLL in layer three. The advantages of MVC: Low coupling, high reusability, fast deployment, maintainability.6: Different layer architecture advantages and disadvantages1 or 2-tier architectureAdvantage: With fewer processes and layers, applications with a small number of users are simple and fast to deploy, while low-cost hardware and network maintenance. Disadvantage: But when the number of users increases, there will be big problems. Since only 1 to 2 computers can be deployed, there are limitations in terms of security, scalability, and fault tolerance of the program.N-tier ArchitectureAdvantages: 1, scalability. This is due to the multi-layered function and low coupling of the decision. For example, because there is no other layer of coupling, the data layer can expand the database cluster, the Web client can be extended by the load balancer without affecting the other tiers, Windows Server can easily cluster through load balancing and failover. 2, can be security. Better and more secure control over the entire system, we can implement different security policies for each layer, for example, the business layer and the data layer usually require a higher level of security than the presentation layer, and we can put these two high security layers behind the firewall for protection. 3, can be fault-tolerant. For example, without affecting the other layers, the database can be failed over in the data tier and load-balanced clusters. 4, can be independent. Independent upgrades and changes can be made without affecting the other layers. In an object-oriented world, an interface-dependent implementation can decouple all layers very well, so that if one of the layers changes, the impact on the other layers is very small or even unaffected. Interface dependencies mean that layer-to-layer communication is communicated to each other only through interfaces, and one layer depends on the interface of the other layer, not the inner class. Of course, when changing the whole system, the dependency of the layer affects only his low-level implementation, which minimizes the effect of the side effects. For example, if the interface does not change, without affecting the entire system, we can change or replace the layer implemented by this interface. 5, it is convenient. A more convenient and efficient development environment, decoupling is mainly through the combination of software components to implement a module, so software development is very convenient and efficient. Each layer to achieve the function can be assigned to different development groups, simply through the interface to communicate with each other, each layer can do their own unit testing, to the final completion of the combination of the system into a complete. 6, maintainability. 7, scalability. Since the business development is component-based, it is very convenient to add and remove new features. 8, reusability. Because it is high cohesion and low-coupling, common functionality and code can be reused, or it can be called by other applications. Disadvantage: 1, because many networks, computers and processes are independent operation, once the system hardware and network bandwidth is poor, the overall system performance will be slower. 2, if you need better hardware and network bandwidth, the cost of hardware and network, maintenance and deployment is high.7: Business data validation in multi-tiered architecturesIn a multi-tiered architecture, data validation is a very necessary and important step in order to ensure the health and well-being of the entire business system. So first there's a problem with data validation? Which layer should we validate and where do we validate it? Here are a few points: 1, you can validate data in any layer. Typically, the closer the data validation is to the customer tier, the more efficient it is. The farther away from the client, the more reliable and robust it needs to be. 2, we need to deal with the balance between performance, reliability, and robustness when deciding which tier to use for data validation. 3, client-side validation is a very effective means, such as: JavaScript client authentication, when at the same time, users can easily bypass client authentication, such as what web hackers do. Therefore, when considering performance and reliability, data validation at the client and service is very much needed. 4, for some data interaction applications, whether we will be on the server side to verify, we need to do acceptable data validation on the client.8: Development skills in multi-layered architecturesDesigning, maintaining, implementing, and deploying in a multi-tiered architecture is a daunting task. If there is no clear plan at the beginning, then it is possible that the late development will be useless. Here are a few suggestions: 1, with some loosely coupled techniques, as much as possible to decouple the relationship between layers and layers, such as soap XML or interfaces. In object-oriented, each layer relies solely on the specific layer it implements directly, rather than through clustering. This allows us to decouple as much as possible, and it will bring greater benefits to our later development, such as unit testing, maintenance, system upgrades, scalability, and reliability. 2, as much as possible automatic generation technology or for the entire system, through the Poco version of the business entity maintenance. The use of features, partial classes, DTOs and other methods. 3, use some automated tools or packages for entity mapping between business entities and traditional relational databases. Tools such as the entity Framework and NHibernate. 4, take advantage of the code generator. 5, we should try to avoid the high coupling between the business layer and the persistence layer. For example, it is common for us to have direct access to the entity Framework through WCF Business services. But one problem with this is that the business layer and the persistence layer are highly coupled. This high coupling can lead to more problems. Usually we use an adapter to solve this coupling, and then turn the high coupling into loose coupling, they only communicate through the interface. 6, at the customer presentation level, we abstract and encapsulate the common code to achieve common purpose. 7, in order to improve performance, often to increase the cache. 8, in order to adapt to changes in requirements, a good multilayer architecture can easily handle the scalability and configuration flexibility of the deployment.9: ConclusionThis paper describes the concept and definition of multi-layer architecture, and introduces the typical representation in multilayer architecture-"Three-tier architecture". It also shows that a complete three-tier architecture should be a presentation, application, and data layer running on separate computers. and describes the relationship between the three-tier architecture and the MVC architecture, which should belong to and belong to the relationship. This paper analyzes the advantages and disadvantages of multi-layered architectures, the importance of data validation in multi-layered architectures, and finally illustrates some of the tools and techniques that can be used in multi-layered architectures, remembering that communication between layers and layers is interactive through interfaces, rather than clustering, so that the high cohesion and low-coupling of communication are achieved when developing modules.
This is the study of "N-tier Architecture and Tips" This article thinking, if there is misunderstanding, hope to enlighten. Original reference: Http://www.codeproject.com/Articles/430014/N-Tier-Architecture-and-Tips
Some thoughts on multi-layer architecture