Summary of my Architecture Experience (III)-in-depth three-tier architecture

Source: Internet
Author: User

Summary of my Architecture Experience (II)-I have already thoroughly introduced some experience in L3 architecture. Now, let's take a closer look at what I understand with a lower scale.

I. Three-layer architecture

 

2. responsibilities at all levels of the system
1. The UI (User Interface) layer is responsible for data presentation and collection. The data collection result is usually submitted to the BL layer as an Entity object. The Service Interface layer is used to publish business or data resources as services (such as WebServices ).
2. the BL (Business Logic) layer is responsible for processing requests submitted by the UI Layer according to the predefined Business Logic.
(1) The Business Function sub-layer is responsible for implementing basic Business functions.
(2) The Business Flow sublayer organizes multiple basic Business functions provided by the Business Function sublayer into a complete Business Flow. (Transaction can only be enabled at the Business Flow sublayer .)
3. The ResourceAccess layer is responsible for providing comprehensive support for resource access and shielding the source of resources from the top layer.
(1) BEM (Business Entity Manager) Sub-layer uses the DataAccess sub-layer and ServiceAccess sub-layer to provide the basic data/resource access capabilities required by the Business.
(2) The DataAccess sub-layer is responsible for accessing resources from the database and shielding the BEM sub-layer from all SQL statements and database type differences.
The DB Adapter sub-layer is responsible for shielding the differences in database types.
The ORM sub-layer is responsible for providing object-link ing.
The Relation sub-layer provides data access capabilities based on Relational that cannot be completed by ORM.
(3) ServiceAccess sub-layer is used to obtain resources from external systems in the SOA mode.
Note: the Service Entrance is used to simplify access to the Service. It is equivalent to the Service proxy. The customer can directly use the Service Entrance to access the Service released by the system. Service Entrance provides strong interfaces for specific platforms (such as Java and. Net), which may hide complicated parameter type conversion.
(4) The ConfigAccess sub-layer is used to obtain the configuration object from the configuration file or save the configuration object to the inverted configuration file.
4. The Entity side layer spans the UI/BEM/ResourceManager layer and transmits data between these layers. The Entity side layer contains three types of Entity, as shown in:

 
Iii. Aspect
Aspect runs through all layers of the system and is a cross-cutting concern of the system. AOP technology is usually used to model and implement cross-cutting concerns.
1. Securtiy Aspect: used to support the Security of the entire system.
2. ErrorHandling Aspect: the entire system adopts consistent error/exception handling methods.
3. Log Aspect: used for system exceptions, Log records, and Business Operation Records.

Iv. Rules
1. No cross-layer invocation is allowed between all levels of the system and its sub-layers.
2. Entity object transmits data between layers.
3. Data bound to the list on the UI Layer is transmitted using a relational DataSet. In addition, Entity object should be used to transmit data.
4. Each database Table corresponds to a DB Entity class, and each Entity class corresponds to a BEM Class.
5. Some cross-database or cross-Table operations (such as complex joint queries) also need to be supported by the corresponding BEM Class.
6. For a relatively simple system, consider merging the Business Function sub-layer and Business Flow Sub-layer into one.
7. The UI Layer and BL layer prohibit any SQL statements.

5. Errors and exceptions
Exceptions can be divided into system exceptions (such as sudden network disconnection) and business exceptions (such as user input values out of the maximum range). Business exceptions must be converted into the results of business execution.
1. The DataAccess layer must not hide any exceptions on the upper layer (almost all exceptions thrown by this layer are system exceptions ).
2. clearly differentiate the results of business execution and system exceptions. For example, to verify the validity of a user, if the corresponding user ID does not exist, an exception should not be thrown. Instead, an enumerated value (or an out parameter) indicating the verification result is returned, which is the result of business execution. However, if the database connection is suddenly disconnected when user information is extracted from the database, a system exception should be thrown.
3. In some cases, the BL layer should capture certain system exceptions based on business needs and convert them into business execution results. For example, if a business requires testing whether the specified database can be connected, BL needs to convert the system exception of database connection failure to the result of business execution.
4. in addition to the return values obtained by calling the API of the BL layer to view the Service execution results, the UI Layer (including the Service layer) also needs to intercept all system exceptions, and interpret it as a friendly error message to the user.

Vi. Project Organization Structure
Take the BAS system as an example.
1. Main directory structure:
 
2. namespace: the root namespace of each dll is the name of the dll. For example, the root namespace of EAS. BL. dll is EAS. BL. Under each root namespace, sub-namespaces can be added based on the categories required, for example, EAS. the sub-space EAS of BL. BL. order and EAS. BL. permission processes different business logic respectively.
3. Physical organization that contains a large number of sub-projects:
 
Core location of Core sub-projects:

 
Core sub-projects include some public infrastructure, such as error handling and permission control.

7. Publish services and service callback
Take the EAS system as an example.
 
1. like the Page on the UI Layer, the service cannot throw any exceptions. Instead, it should return an error code (int type, 1 indicates success, and other values indicate failure) indicates that a service call has an error. If the method returns a value, the return value is provided as the out parameter.
2. If the BAS system provides the WebService (Remoting) service, BAS must provide BAS. Entrance. dll. BAS. Entrance. dll encapsulates the communication mechanism for exchanging information with the BAS service. The customer system can easily access the services provided by BAS. Entrance. dll through BAS. Entrance. dll.
3. if BAS needs to call back the customer system through WebService (Remoting), it must provide BAS that only define interfaces. callBack. dll, the customer system will reference this dll, implement the interface, and publish it as a service for BAS callback.
4. when the WebService parameter or return value must be of a complex type-namely, the Service Entity in the architecture diagram, the Service Entity should be in the corresponding BAS. entranceParaDef. dll or BAS. callBackParaDef. dll. The complex types of WebService-defined methods should be replaced by Xml strings (note that the parameters of the methods corresponding to the Entrance and CallBack interfaces are strongly typed ), the conversion between Xml strings and complex types of objects should be in BAS. entrance. dll or BAS. callBack. dll.

 

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.