Enterprise Application Architecture Patterns of Enterprise Application Architecture

Source: Internet
Author: User
Tags in domain to domain
Domain Layer
Patterns

1.
Transaction Script

Organize Business Logic by procedures that carry out what needs to be
Done in a transaction.

Use the process to organize the business logic. Each process completes the processing of a request.
2.
Domain Model
Build
Object model of the domain that inmarshate both behavior and
Data.

The domain model should use fine-grained objects, but the performance of fine-grained objects for remote interfaces is not good. A Service should be used when fine-grained objects are used.
Layer implements coarse-grained remote interfaces (avoid remote interfaces whenever possible ).
3.
Table Module
Provide
Single object for all the behavior on
Table.

An object encapsulates all or major business logic of all data in a table.


Transaction scripts and table modules may use some classes. These classes are different from domain models, and their responsibilities are vague and extensive, it only encapsulates and packages some features and business logic at a very rough level.


For a period of time, we have been arguing about two types of Domain Models: the anemia model and the congestion model. The domain model in the book refers to the congestion model, and the object should have data and behavior, the anemia model is usually used to implement business logic
Transaction Script Mode.

We can regard the table module as a transaction script. It mainly processes business logic based on database tables. DataSet, DataTable, and,
DataRow is more convenient to use the table module. The object implementation business logic based on the anemia model is basically Transaction.
Script method.

Taking SRM as an example, the new version of xiaxiao is Transaction Script, and the Web Service of Hisense is Transaction.
Script.


Object/Relational Mapping
Patterns

1. Active
Record
An object that wraps
Record data structure in an external resource, such as a row in
Database table, and adds some domain logic to that object.
Activity logging is essentially a domain model. Its classes match the data structure in databases, and database access operations and domain logic are all placed on objects. Activity records can be viewed as a coarse-grained domain model.
2. Row Data Gateway
Row Data Entry
An object that acts as
Gateway to a single record in a data source.
A class instance operates on a row of data. The anemia model usually uses the row Data Entry Method to map a single record in the database to the anemia model object. In addition, activity records can naturally use the row data entry method.

3. Table Data Gateway
Table Data Entry
An object that acts as
Gateway to a database table.
An instance of a class operates on all data in a table. SQL is usually used to perform business logic operations.
4. Data Mapper

Transfers data from a domain object to a database. The Data
Mapper is a layer of software that acts as a mediator between
In-memory objects and the database.


If the er is hard-coded, it is best to use a data ER for each domain class or domain layer. If metadata ing is used, one er is enough. Mappers are generally used in Domain Models.
5. Metadata Mapping
Metadata ing
Hold details
Object-relational mapping in metadata. Two implementation methods: code
Generation and reflective
Program. For example, Hibernate metadata is represented in XML, and many frameworks use attribute as metadata.
 
6. Identity Map
Id ing
Ensure each object only
Gets loaded once by keeping every loaded object in a map. Lookup
Objects using the map when referring
Them.
7. Identity Field
Id domain
Save a database id field in
An object to maintain identity between an in-memory object and
Database row.
Meaningful key
Meaningless key:
The ID field may be a GUID, which may be an ascending integer. It is best to extract or construct fields with certain rules and meanings from business analysis as the identification, such as material encoding and sales.
Purchase order number, customer supplier code, factory code, and so on.
Simple
Key vs compound key, table-unique key vs database-unique
Key.
Getting a new key: get
Database to auto-generate, use a GUID, or generate your own. The most
Common auto-generation method is that of declaring one field to be
Auto-generated field, an alternative approach to auto-generation is
Database counter. When using GUID, the platform generally provides the GUID generation API. The last option is rolling
Your own. For example, use the max function of SQL to find the next sequence. A better approach is to use a separate
Key
Table.
8.
Serialized LOB serialization LOB
Save
Graph of objects as by serializing them into a single large object
(LOB) and store the LOB in a database
Field.

For example, if the company's organizational structure is a tree without considering association or other factors, You Can serialize the tree and save it as a field. BLOB (Binary) or CLOB (text) fields can be used in the database.

9. Foreign Key Mapping
External ing
10. Dependent Mapping
Dependency ing
Have one class perform
Mapping for another.
The dependent party has only one owner and is not referenced by any other object. In this way, when the owner is loaded, all dependent persons can be loaded at the same time.
 
11. Association Table Mapping
Associated table ing
Save an association as
Table with foreign keys to the tables that are linked by
Association.
12. Embedded Value
Aggregate Mapping,
Composer)
Map an object
Several fields of another object's table.
For example, in the date range, a resume may be a DateRange object, while in the database, two fields may be used: StartDate and EndDate.
13. Lasy Load
Delayed Loading
An object that doesn' t
Contain all of the data you need, but knows how to get
It.
Lasy
Initialization (delayed initialization), Virtual proxy (Virtual proxy), Value
Holder and Ghost ). There is no need to use delayed loading for common fields. It is appropriate to use delayed loading for a single cohesive and correlated collection object.

14. Concrete Table Inheritance
Specific table inheritance
Represent an inheritance
Hierarchy of classes with one table per concrete class in
Hierarchy.
It can also be called leaf table inheritance. Only the leaf node class in the inheritance relationship has the corresponding table.

15. Single Table Inheritance
Single Table inheritance

All classes in the inheritance structure are saved in one table.
16. Class
Table Inheritance class Table Inheritance

Represent an inheritance hierarchy of classes with one table for each
Class.

Web
Server Patterns

1.
Model View Controller
2. Page
Controller page Controller
An object that
Handles a request for a specific page or action on a web
Site.
As a result Page
Controller has one input controller for each logical page of the web
Site. That controller may be the page itself, as it often is in server
Page environments, or it may be a separate object that corresponds
That page.

Generally, the separation between the model and the presentation layer is obvious, while the separation between the view and the controller is fuzzy. ASP. NET Code
Behind mode, the Controller of each page is a separate object; ASP, ASP. NET Code
In the Inline mode, the controller is the page itself.
3. Front
Controller front-end Controller
A Front
Controller handles all callfor a web site. It's usually structured in
Two parts: a web handler and a hierarchy of commands. The web server
Software directs the http request to the handler. The handler pulls
Just enough information from the URL and request to decide what kind
Action to initiate. The handler then delegates the request to
Command, which usually isn' t a web handler, to carry out
Action.

Maverick. Net is a front-end controller. In essence, Code Behind is no different from Maverick. Net in terms of ideology. Code
The Behind view is closely integrated with the Controller, so it is easy to regard them as one. When solving the problem, the idea is bound with the page, which easily leads to the shift of the understanding and implementation of the business logic to the page, fade
The concept of Model is used to describe the concepts between MVC. Maverick. Net has a clear separation of MVC and is conducive to Domain
Use of Model.
4. Template View
Template View
Render information
HTML by embedding markers into an HTML page.
Server Pages such as ASP and ASP. NET Are Template views.
5. Transform
View conversion View
A view that process
Domain data element by element and transforms it into HTML.
XSLT conversion is widely used, which requires that the Model be serialized into XML.

6. Two Step View Two-Step View
Turn
Domain data into HTML in two steps: first by forming some kind
Logical page, then rendering the logical page
HTML.

The first step is to convert the Model data to a logical representation without any detailed format information. The second step is to convert the logical representation to the final format. If the page uses the currently popular DIV +
CSS layout can reduce the reason for adopting the two-step view to a certain extent.
7.
Application Controller
A
Centralized point for handling screen navigation and flow of
Application.
Similar to Action Flow
Engine, in the business logic is very complex, but requires considerable flexibility, so some Command processing may be quite complex, using an Application
The Controller facilitates logical splitting and reorganizing.

Base
Patterns

1.
Gateway
An object that
Encapsulates access to an external system or resource.

One of the key uses for
GatewayIs to make a good point to apply
Service Stub. KeepGatewayAs
Simple as you can. Focus on the essential roles of adapting
External service and providing a good point
Stubbing.
2. Record
Set
An in-memory representation
Of tabular data.
For example, DataSet of ADO. NET.
3. Value
Object
A small simple object,
Like a money or date range, whose between ity is not based on
Identity.
4.
Money
Represents a monetary
Value. is a type of value object.
5.
Plugin
Link classes
Configuration rather than compilation.
Eclipse and SharpDevelop are successful plug-ins. If plug-ins are used, it is necessary to have a detailed understanding of OSGI specifications.
Standardized application.
6. Service
Stub
A stand-in implementation
Of an external service.

If a project depends on services of a third-party system, many unpredictable problems may occur during the development process, and testing is also troublesome. This problem is solved by using the service pile. The first step is
To define access to this service with an interface. Once the interface
Is defined and an implementation or two has been coded it's simply
Matter of using the Plugin pattern to provide the proper
Implementations of services to your application
Runtime.
7. Layer
Supertype
A type that acts
The supertype for all types in its
Layer.
This mode is also frequently used, for example, all Domain
Objects may inherit from a super-type, Service
Classes in Layer may also inherit from a super type.
8.
Special Case
A subclass which
Provides special behavior for Particle
Cases.

Classes that handle special situations, such as Nullable classes.
9.
Registry
A well known object
That other objects can use to find common objects and services.
The registry mode is easy to use. In some cases, it can also skillfully solve some problems, such as Dialect in Hibernate.

Distribution
Patterns

1. Remote
Facade remote appearance
Provides a coarse
Grained facade on fine grained objects to improve efficiency over
Network. As well as providing a coarse-grained interface, several other
Responsibilities naturally go toRemote Facade.
The methods ofRemote FacadeAre a natural point
To apply security.Remote FacadeMethods also
Are a natural point to apply transactional control.
The remote appearance should not contain any domain logic. If workflow or collaboration logic is required, it should be placed into a fine-grained object or a transaction script, the entire application must be able to work without the remote appearance
.

The remote appearance is different from the service layer. The service layer does not need to be a remote method without a coarse-grained method, and the service layer does not need to use a data transmission object. It returns a real domain object to the client.


Martin experience: for medium-sized applications, a remote appearance is sufficient, and a large system uses 5 or 6 remote appearances.

2. Data Transfer Object
Data transmission object
An object which acts
Purely as a carrier of data in order to reduce method CILS.
Generally, one reason for choosing the anemia model is that domain objects can be easily used as DTO.

Concurrency Patterns
1. Unit of Work Unit
Maintains a list of objects that are affected by a business transaction and
Coordinates the writing out of changes and resolution of concurrency
Problems. similar to caching, for example, a transaction requires multiple UPDATE operations. As a work unit class, multiple updates are first cached and multiple update SQL statements are submitted when a transaction is submitted, to reduce concurrency conflicts.
Therefore, Hibernate uses the Session mechanism. A Role of the Session is the unit of work.

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.