Mainly resolve how to separate data from the application from the application. This issue will encounter this problem as long as the application deals with the database. Traditional C / S architecture uses most of the code of data access and application, there are several aspects: o Tight coupling with specific database technology, such as our company's products based on SQL Server, now very Difficult to switch the Oracle, do not say to future new technologies - xml databases or object-oriented databases; O application is tightly coupled to the data model, lack of elasticity. o It is difficult to optimize, each module is written by different programmers, but not everyone is good at the development of the database, so the efficiency of the program is low, but optimizes these code costs is quite expensive; o is not convenient for maintenance, When there is a problem, it is not easy to find the source of the problem - from business logic or data access logic; this part introduces four modes:
o Data Accessor
o Active domain object
o object / relationship mapping
O layer
Chapter 1: Data Accessor (Data Accessor) Mode
Brief description
"Encapsate the physical data access details in a single component, only public logic operations. Application code reserves the knowledge of the underlying data mode, but only separates with data access."
Package principle
o Public logic operation, encapsulation physical operation -, for example, using a SQL statement directly using the SQL statement.
o Public logic resources, encapsulate physical resources - make full use of resources, such as connectivity.
o Package platform detail - platform irrelevant.
o Pack Optimization Details - Place the optimized elasticity in the data accessor, not the application code, so that it can be uniformly optimized.
applicability
o requires the complexity and platform issues of physical data access to application logic.
o Semantic positions provided by the underlying physical database driver requires management additional semantics. For example, the lock mechanism of the application level.
o Need to define multiple data access implementations and choose from during runtime.
advantage
o Clear Application Code - Application code that is full of data access details is difficult to read and maintain, use the data accessor to make the application code more set to its own business logic.
o New database features or platforms - If the data access code is distributed throughout the system, if you want to use the new database characteristics (such as switching from the SQL Server platform to the Oracle platform), you will browse and modify the code of the entire system, and use Data Accessors can encapsulate this detail into a component.
o Combined Optimization Strategy - When adjusting the application performance, data access code is often the primary analysis focus. The same use data accessor can be used to introduce an optimization policy to the entire system.
o Exchangeable physical data access implementation.
Disadvantage
o Limits the application of the application to data access - requesting the data accessor design to have sufficient versatility.
Strategy
o Define universal logical operations - on the one hand, pay attention to versatility; do not introduce unnecessary complexity in the other hand, can solve this problem by research cases. I feel that the accumulation of experience is also very important.
o Leave Optimization and Improved Location - The function is often sacrificed during the development process to ensure progress.
o Prevents the application of the application from offset.
Instantiate
o SingleTon Data Accessor Implementation.
o Initialization and parameter transfer - Dampoints are required to define an additional parameter in the constructor and operation of the class.
o Data Accessor Factory.
Chapter II: Active Domain Object Mode
Brief description
Package data model and data access details in the relevant domain object implementation. Active domain objects allow application code to avoid any direct interaction with the database.
Active is that the domain object is not just a simple representation of data, and the logical operation (initialization, refresh, saving, list) is also disclosed, which completed most related database interactions for their data. Operation names are named using the domain.
applicability
The complexity of physical data models and data access is required to be hidden in application logic.
All data models and data access details on a certain domain concept are packaged in a single component. The inconsistency and 涩性 性 - of the application logic hide the data model - the advice of legacy data.
advantage
Clear application code
Decoupling application code and data model
Tissue related data access code into a single component
Disadvantage
Data Access distribution in multiple domain objects
Limited the application of application on data access
Chapter 3: Active Domain Object Mode
Brief description
Blocking the domain object and the mapping between the domain objects and the relational data in a single component. Object / Relationship Mapping simultaneously separating application code and domain objects from the underlying data model and data access details.
applicability
It is necessary to hide the complexity of physical data modes and data access to applications logic and domain objects.
You need to block the domain object mapping in a single component so that you may not modify the application code or domain object definition when the data model changes.
Need to map multiple data models from domain objects without modifying the versatility of application code or domain object definitions.
trade off
Rely on additional commercial products
advantage
Clear application code
Map to replaceable data model
Disadvantage
Limited the application of application on data access
Chapter 4: Layers
Brief description
The orthogonal application characteristic of the processing data access problem is stacked in the incremental abstraction layer.
applicability
It is necessary to separate data models, data access details, domain object mappings, or other orthogonal features that are prepared independently modified.
It is necessary to define multiple incremented software abstraction layers to simplify development and maintenance.
It is necessary to establish a prototype or use the stub or simplified layer to implement step-by-step construction system, and fill in more flexible or optimized implementation during future development - let it work, then make it better.
advantage
Software design decomposition
Data Access Features Modular
Data Access Detail Package
Multi-layer implementation of pluggable
Disadvantage
Complexity of interacting and initialization
summary
The four modes described in the decoupling mode are mainly solved by separating the persistence of data from the application logic. The main meaning of this is to make the application code clear, put the main major energy in demand and function; on the other hand, the alternative - dependent on the interface is not dependent on the implementation; The level of abstraction can also guarantee the quality of data access code - thus ensuring the performance of the system.
Data Accessor Mode is solved by the underlying thing - the abstraction of data access details.
The active domain object and object / relationship map two modes solve how to separate the data model from the application code, but they use different ways to implement object models and relationship models, only one is dispersion One is a concentrated; a self-reliance, a product dependent on ready-made products (not absolute).
This mode gives a solution for further decomposition - the abstract division is a plurality of layers.