Application System Architecture Design-Summary

Source: Internet
Author: User
Tags dotnet

Application System Architecture Design-Summary

If the Simonw@2005.10.27 is reproduced, please indicate the source
Address: http://simonw.cnblogs.com/archive/2005/10/27/263145.html

On the surface, we are developing a variety of different applications. In fact, the corresponding architecture design is relatively stable. Programming in a good architecture is not only a pleasing thing for developers, but more importantly, the software can show a healthy posture. The architecture design is unreasonable, not only do developers suffer, but the life cycle of the software itself is even more under severe threat. Here I willDOTNETThe system architecture design for application development on the platform is a rough discussion.

 

Overall Design Drawing

 

 

Presentation Layer

Presentation LayerUI(User Interface) AndUIControl logic.

    • UI(User Interface)

UIIs the user interface of the client. It receives commands, requests, and data from the user, passes them to the business layer for processing, and then presents the results. Based on different clients, we generally applyProgramDividedBS(Browser-Server) Browser structure,CS(Client-server) Desktop client structure.

BSThe advantage is that you only need to deploy and maintain the server without worrying about the client.CSThe advantage is its powerful interface interaction and expression capabilities.Ria(Rich Internet Application) Is a technology that integrates the advantages of these two structures, it relies on the one-time installation of a universal interpreter on the client to obtain powerful interface interaction and convenience without the need to deploy a specific client. There are many specific implementation technologies, such as Microsoft'sSmartclient,Aveon;MacromediaOfFlex;JSBasicBindows;AjaxAnd so on. 

    • UIControl Logic

UIControl logic processingUIData Interaction with the business layer,UIControl the status process, and be responsible for simple data verification and formatting. SpecificallyDOTNETUnder the event-driven programming model,UIThe control logic is implemented in the event function, for examplePageloadEvent functions,ButtonclickEvent functions. Among these event functions, the main task is to doUIData exchange and service calling between controls and business entities have become the biggest problem in the face of a large amount of data exchange workload and maintenance workload. In a complex application system, state and process management must be considered. It includes two aspects: interface and business. If it is written directly in the event function without being encapsulated, the business will depend on the presentation layer. The two questions are discussed below. 

1. UIData Interaction with business entities

The business entity responsible for data exchange at this stage is called Dto ( Data transfer object ), But it must be noted that Dto It is not a business object that only contains data. It still contains the complete business entity as necessary. When processing input, we start from UI Enter the data obtained by the Control Dto And then Spread Downward. when processing the output, the user sends a request to the business layer Dto In the form UI Control display. Therefore, we need a way to automatically solve the problem of round-trip assignment. Java Lower Structs Of Formbean I have provided some support for this problem. Unfortunately DOTNET Although many controls support data binding, there is still no complete solution. One simple way is to design one by yourself. Adapter Automatically handles such binding according to a certain ing relationship. Such ing relationship is best UI Controls and Dto Prior naming conventions of attributes, which can be used as mappings without adding any configuration files or configuration work. For example Textbox Name it Txtusername And my business entity attributes are named Username In this way, you can find the corresponding string by searching.  

2. Status and process management

the status and process of complex businesses can be implemented through some workflow engines. solution, microsoft recently released its own workflow engine. If you are interested, you can check it out. Generally, you need to manage the status and process on the interface. Coupling is not desirable in the presentation layer. MVC ( Model-View -controller ) mode provides methods to achieve this goal. controller is the core of the entire solution. It is a process manager, from UI All commands and data pass through controller distribute to business layer or other UI , in this way, we can encapsulate the process, permissions, and other logic separately, such as in the configuration file, to maximize business reuse. DOTNET MVC solution does not have as many options as JAVA , currently, the following options are available:

MicrosoftUipab, It can handleBS,CSTo make the same business system haveWebformAndWinformDifferent display methods.

Open-sourceMavrick. net, It only appliesASP. NETApplication, which is used for process, internationalization, page packaging,XSLTPage conversion provides good support.

Open-sourceLattis, The function is relatively simple, the same applies onlyASP. NETApplication.

 

Business Layer

The business layer encapsulates the actual business logic, including data verification, transaction processing, permission processing, and other business-related operations. It is the core of the entire application system. Therefore, it is necessary to design a business layer that truly reflects the actual needs. We divide the actual business into two parts: business data and business operations. 

    • Business Data

The business data is the core of the business logic. The final business data will be displayed in the memory in a fixed format and transmitted between different levels of the system.DtoRole. There are two ways to express business data:Table ModelAndDomain Model.

table model directly maps tables in the database to business data objects, this method is suitable for machine operations. ADO. net directly facilitates this operation, but it is not intuitive to express complex business relationships. It is only suitable for quick development where the business needs correspond directly to data tables. Generally, dataset or strong dataset ( strong Typed Dataset ), strong dataset supports type check during compilation, the efficiency is slightly higher than that of normal dataset . dataset has many convenient features: you do not need to write maintenance classes and support serialization, data copies are saved, and data sets are supported, and control binding is well supported. Microsoft provides corresponding generation tools and persistent solutions. However, the disadvantage is obvious, and complex data is not intuitive. As DTO , especially in distributed environments, the huge volume and relatively slow instantiation put a lot of pressure on performance.

Domain ModelIt is used according to the actual business.OoThis method is suitable for complex business systems. Generally, the user-defined data entity (Custom Data entity. Custom Data entities have good performance. The type check during compilation has the advantages of intuitive data presentation in line with actual business operations. However, you need to define your own maintenance classes, in a distributed environment, you must compile your own serialization method.

Based on various factors, although the business is simple and corresponds to a direct systemTable ModelModeling and development efficiency is very high, but it is inevitable that the system will not become complex in the future. Therefore, it is selected for reusability, scalability, and performance.Domain ModelModeling is preferred. 

    • Business Operations

Business Operations are responsible for processing business data, such as verification, flow direction, integration, transactions, and permissions. However, they are not responsible for operations on data sources. Its relationship with business data is designed to be2Method.

Separate business data from business operations, and encapsulate business data separately to only dataGet,SetIn the data class, this data class only actsDto. Encapsulate business operations into independentServiceClass and business data act as the business layer. In this way, the system is simple and intuitive when it is not complex, and as the system becomes increasingly complex,ServiceClasses become messy, and separating the tightly coupled data from operations is also a negative factor for reuse. For details, referMartin FowlerOfAnemiaDomain ModelArticle.

Integrates business data and business operations, encapsulates business data and related business operations, and is called a business entity. The business entity acts as a unified business layer to provide services for the presentation layer, and is also responsibleDtoI prefer the completeDomain ModelDesign method, each business entity can exist as a separate component form, which has great benefits for componentized reuse.

 

Business Data access layer

The business data access layer is an exclusive layer for specific application systems. It provides the minimum operation mode for the business layer to interact with data sources. It is only the data access interface required by the business layer, the business layer relies entirely on the services provided by the business data access layer. These services receive data from the business layer or return to the business entity, which shields the differences between actual business data and machine storage methods. Of course, the data layer can achieve this by selecting an abstract solution, but the biggest feature of the business data access layer is to abstract specific businesses, the abstract data layer access scheme is abstracted for general purposes. The specific design in the business tends to become more powerful, so that we can maximize the upper layer.CodeIf the data layer access is too different and the data layer cannot solve the problem, we only need to change the business data access layer, instead of changing the business layer. 

Business Data access layerDao(Data Access Object) Layer and system service layer.DaoThe system service layer provides the most basic data access services for each business entity. The system service layer provides general data access services that do not have much to do with the business. These two layers are located at the same level in the system.

 

Relationship between business layer and business data access layer

 

 

Data Layer

The purpose of the data layer is to provide an interface for external access to the data source. We should choose an abstract data access interface that can provide data source independence and connect differentDataproviadorTo access the data layer components of the data source. Currently, the following3Data layer solution: 

1.EncapsulationAdo. net

all these Data Access Components are based on ADO. net , which has the advantages of low encapsulation layers and the fastest speed, you can manually organize SQL statements to adapt to complicated operations and optimize individual features. The disadvantage is that you cannot directly process the business entity objects in the Custom Data entity mode. You need to pass the data attributes in the business entity as parameters. Although this method is the safest, development efficiency, quality, maintenance, and secondary development become particularly prominent as the system grows, developers are increasingly demanding. In addition, the encapsulation of transaction operations is not very good, and declarative transactions cannot be provided. Therefore, access to the data layer is often required at the business layer. Such components are widely used at present, for example, Microsoft enterpriselibrary daab ( data access Application Block ), the previous daab3.1 . enterpriselibrary is a mature product, including data access, exceptions, logs, and caches, encryption, configuration , Security and other components are ideal for general services.

2.Or-MappingComponents

ORMIs the best data persistence solution. It has the advantage of being able to manipulate data in an object-oriented manner, so we can directly process the Business Objects of custom data entities, so we don't have to worry about it.SQLStatement and the underlying storage method, which greatly simplifies the code and improves the development efficiency, greatly facilitating the maintenance and expansion in the future. The disadvantage is that the underlying layer is shielded so that we cannot optimize the specific data source, and the complex associationSQLThe operation is not powerful, and the performance is also poor, but the cache-assisted operation is much better.DOTNETThe biggest problem is that there is no mature and cheapORMAll products are for use.BetaVersion and commercial version. These versions have more or less problems, so the real application needs to be carefully examined. For exampleNhib.pdf,Gentle. net,Xpo,Grove. netAnd so on. 

3.Datamapper(Sqlmapper)

SqlmapperThe preceding two methods provide a compromise. They can directly process the Business Objects of custom data entities in an object-oriented manner, at the same time, you can execute handwriting Based on the ing relationship between the data source and the business entity.SQLStatement, which allows us to optimize specific data sources and be competent for complex operations. Currently onlyIbatis. netA product isJavaThe new open-source project is mature and can be replaced without compilation.Dao.

 

Dependencies between layers

Dependency diagram:

 

After the discussion of each layer, We will summarize the dependencies between the layers. When it comes to dependency, the word reuse is inseparable. reuse is of great significance to almost every stage of the software development process. In the design stage, it represents a clearer design. In the development stage, it represents higher work efficiency and code quality. In the test stage, it represents easier to captureBugIn the maintenance and redevelopment stages, it represents a smaller workload. Better reuse requires better dependency design. 

It can be seen that both the presentation layer and the business data access layer depend on the business layer, and the business layer is relatively independent. The advantage of this design is to minimize the impact of changes on the entire system. The worst case is the business change, where the business changes other dependent business layers must be changed (Here we ignore some other layer components designed for multiple businesses, these components can adapt to limited business changes without changes .), There is no way to control this. However, other non-business changes such as the presentation layer and business data access layer will not affect other places. 

Someone should have noticed the configuration file in the figure. Without it, the business layer depends on the business data access layer. careful readers should be able to find this problem from the relationship graph between the business layer and the business data access layer. In this way, the two-way dependency is the root cause of future unavailability. Therefore, you need to abstract the business data access interface so that the business layer can depend on this interface, rather than the business data access layer. However, it is not enough to declare an interface, because a specific lower-level class is still required during instantiation, so the dependency still cannot be escaped. So the dependency is transferred out, which leads to dependency inversion ( Dependency inversion principle ). For more information, see Martin Fowler . IOC ( Inversion of Control ) The container provides us with a perfect solution. By injecting different modules into the system, we can call it without knowing the component exists. This method is also suitable for permission management, mail sending, and other components. Spring. net And Castle Yes DOTNET Two excellent IOC Container Spring. net Yes Java Lower Spring , Castle Relatively more mature. However, when you are not using many components rather than configuring these complex and powerful products, you need to do this manually, you need to write the Data Access Components used by the business layer in the configuration file, and then use ( Factory ) Parse the configuration file application reflection ( Reflection ) Technical instances are used to generate your components.  

Finally, let's talk aboutAOP(Aspect-orientedprogrammingIn some very common components or system functions.AOPTechnology to eliminate the dependency of other parts of the system on them. Such as permission management, system logs, and exception handling. Take permission management as an example. We usually add a row of permission detection code at the beginning of the function that requires permission detection. If this code is passed, the code will be executed or the code will jump out. Such writing destroys the purity of the business. The permission of the business does not matter, and the Business Code depends on the permission component, this is troublesome when I need to remove permissions and create a new system.AOPThe advantage is that you can handle these problems in a declarative manner. For example, you only need to add a line of attribute description before the function to be verified or write the functions to be verified in the configuration file.AOPThe components will execute your code in a predefined order, so that we can easily strip these components without affecting the existing system.

 

About Service Layer Discussion

ServiceA layer is a layer built on the presentation layer between the business layers. It is a lightweight encapsulation of the business layer and should not encapsulate too many business logic, otherwise it will cause unnecessary trouble. However, it is not always necessary. In one case, when yourUIWhat you want to display is not exactly the same as your business entity. For example, your interface needs to display a part of several business entities, but this is not the business itself, it is just a display method. At this time you needServiceLayer is used to convert the presentation logic. Or you can useServiceLayer to implement a coarse-grained service interface. You can alsoSOA(Service-Oriented Architecture).ServiceLayer, we end up using the services provided by the system rather than the business objects, so we need to organize the business objects in a clear way to form a clear service exposure. In more cases, how can you use it based on the actual situation.

 

Conclusion

now, the entire architecture solution has been discussed, we can see that the solutions available under DOTNET are so limited, looking back at JAVA in the world, there are so many mature component frameworks available for use, so I am worried. However, DOTNET is maturing, and we need time to wait. The above solution only represents a basic idea and needs to be adjusted in a specific environment. It is expected to play a leading role. For more information about my contact information, see blog . If you are not experienced enough, please correct your discussion.

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.