Mode and J2EE

zhaozj2021-02-08  227

The information engineering is based on the current data system, in the main departments of a business or enterprise, a set of interaction, analysis, design, and composed of construction information systems.

--- James Martin

As the founder James Martin, the founder James Martin of the above information is similar to the concept of the information engineering. The founder of the Patterns, Christopher Alexander, is described below in the Book. (Note: The year behind the book represents the works in different periods, the following forms:

Each pattern describes a problem that occurs around us and the core of the solution. In this way, you can use this solution again and again without having to repeat labor. Each mode is a rule consisting of three parts, which describes the relationship between a specific environment, a problem, and solution. Simply put, there is no model to be an independent entity, each mode is supported, but the level of support is different: the big mode can be embedded in a small mode, the same level mode is paralleled, and the small mode is embedded. In the big mode.

--- Christopher Alexander

The concept of the mode is widely developed in the software industry, and there are now many types of mode applications, including: Gof (Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, 【Design Mode, 1995>, Martin Fowler , Frank Buschmann et al. , Jim O.coplien, Niel Harrison, etc. Human and Deepak aluri et al. , etc., which is the most influential is GOF a book, the book is discussed in detail. Type, a total of 23 modes. A good design is from the accumulation of experience. When designing the standard template, the mode is a powerful mechanism for communication and reuse, and the design and development software can be improved. Mode helps us to organize and record known reproducible issues and solutions in a specific environment, and communicate with others through patterns, which can solve problems that have repeatedly appeared in different environments. Mode allows you to reuse, reuse known solutions to shorten the period of design and development applications, effective usage patterns, allow us to stay away from repeated investment. The key to the mode is to simply and reproducibility.

A simple example of a mode application. For example, running a process in your laptop, and these objects need to communicate with other objects in another process, perhaps this process is not on your laptop, while in other places. You don't want the object in the system to worry about how to find other objects on the Internet or perform remote procedure calls. At this time, you can use the agent (Proxy mode, see the GOF book) mode to solve this problem, what you can do is to build a proxy object for this remote object in your local process, the agent Objects and remote objects have the same interface. Your local object is sent with the message in the usual process and talks with the agent. At this time, the agent object is responsible for transmitting the message to the real object, regardless of where the object is located.

Since the following Java 2 platform (J2EE) application mode is used in the concept of design patterns and reconstruction (refactoring), there is a need to summarize the concept of reconstruction. Reconstruction has been proven to prevent the decaying and decay of software, and the name of the name of the reconstruction is the book written by Martin Fowler, and the book is detailed in detail. Type, a total of more than 70 specific reconstruction techniques, but also point out the importance of testing mechanisms in reconstruction. The Martin Fowler in the book details the concept of reconstruction: Reconstruction is a adjustment to the internal structure of the software, which is to improve its understandability, reduce its understandability without changing the insights of [software]. Modify cost. Reconstruction is a discipline, trained, process-organized method, which can minimize errors that are not careful during the finishing process, essentially, refactoring is to improve its code after the code is written design. Before reconstructed, first check if you have a reliable test mechanism, these tests must have me inspection.

--- Martin Fowler

The J2EE platform based on Java programming language and Java technology is the most suitable application structure of an enterprise-class distributed environment, which is designed to facilitate multi-layer architecture. J2EE includes the following key technologies: Java Service Page, JSP, Servlet, Enterprise JavaBeans (EJB) Components, Java Message Service, JMS, JAVA Naming and Directory Interface (Java Naming and Directory Interface JNDI). Since the J2EE platform is a hierarchical system, we model the hierarchy of J2EE. This model makes us logically to different layers, a total of five levels: the customer layer, representation layer, business layer, integrated layer And resource layers. Because the client layer and the resource layer are not directly concerned about the J2EE platform, the 15 J2EE application modes described later belong to the middle three floors in the top 5, where the representation layer mode contains patterns related to servlet and JSP technology. The layer mode contains modes related to EJB technology, and the integrated layer mode contains patterns related to JMS and JDBC. The specific mode can be found in the table below:

Table 1 represents layer mode

Mode name brief description

Intercept filter (Intercepting filter) promotes pre-processed and post-processing of requests

Front Controller Provides a centralized controller for request processing

View Helper to encapsulate logic to the assistant component with a logical logic that represents layer formatting

Composite view (Composite View) Create a gathering view from the subcomponents of the atom

Worker Service (Service to Worker) combined distributor component, front-end controller and view assistant mode

Dispatcher View (Dispatcher View) combined distributor components, front-end controllers and view assistant models

, Postpone a lot of action to the view processing

Table 2 Business layer mode

Mode name brief description

Business delegate separates the representation layer and the service layer, and provides the appearance of the service

Agent interface

Value Object By reducing network dialogue, data exchange between acceleration layers

Session Facade hides business object resilience, centralized workflow processing

Composite entity (Composite Entity) by grouping parameters into a single entity bean, table

Best experience in designing crude granular entity bean

Value Object Assembler Pieces the value object from multiple data sources into a composite value

Icon

Value List Handler management query execution, result buffer, and results processing

Service Locator Package Service Services Finding and Created Complexity, Location Service

Work factory

Table 3 Integrated layer mode

Mode name brief description

Data Access Objects Abstract Data Source, providing transparent access to data

Service Activator accelerates asynchronous processing of EJB components

Due to the numerous J2EE mode, the space is limited, only one of the application modes-integrated layer data access object (DAO) mode, interested readers can refer to the information in the reference below.

l Data Access Object Mode

1, problem

Data accesses are different depending on the data source. Depending on the type of storage (relational database, object-oriented database, etc.) and vendor, persistent storage (such as database) has a great difference. When a business component (such as a session bean) or representing a component (such as a helper component) requires access to a data source, they can use the appropriate API to obtain connectivity, and operation of the data source. However, in these components, connectivity and data access code are introduced into the close coupling between these components and data source implementations. Such code dependence in the component will make the application migrate from some kind of data source to other types of data sources will become very troublesome and difficult. When the data source changes, the components need to be changed to facilitate processing new types of data sources. .

2, solution

Use the Data Access Object (DAO) to abstract and encapsulate all access to the data source. DAO manages the connection with the data source to retrieve and store data, and the DAO implements the access mechanism for operating the data source. Business components depend on DAO provide a simpler interface for their clients using DAO, and DAO hides the data source implementation detail to the client. Since the interface that the DAO is not changed to the client when the low-level data source is realized, the mode allows the DAO to be adjusted to different storage modes without affecting its clients or business components. Importantly, DAO acts as an adapter between components and data sources.

3. Implement strategy

By adjusting the abstract factory (Abstract Factory mode) mode and factory method (Factory Method, you can see the GOF Book) mode, DAO mode can achieve high flexibility.

l When the low-layer storage does not change with the achievement, the plant method mode can be used to implement the policy to generate a large number of DAOs needed by the application, as shown in Figure 1 below.

l When the low-layer storage changes with the achievement, the policy can be implemented by using abstract factory models. Abstract factories can be created based on factory methods, and can be implemented using factory methods, which provides a DAO abstract factory object, which can construct a variety of specific DAO factories, each plant supports a different type of Persistent storage. Once you get a specific DAO factory for a particular implementation, you can use it to generate DAOs supported and implemented in this implementation, as shown in Figure 2 below. 4, application

When the data access code is directly embedded in a certain type of other unrelated responsibilities, it is very difficult to make changes. At this point, the solution to the data access code can be used, and the data access code is extracted into a new class, and the new class is logically or physically moved to the location of the data source, which enhances the modular and reuse. Sex, as shown in Figure 3 below. Specific methods can use refining classes (EXTRACT CLASS, a reconstruction method, detail to see Martin's One Book) method to create a new class and move data access code into this new data access. Object (DAO) class, use this new DAO object to access data from the controller class.

Example: Persistent logic is embedded in a new DAO object that uses the persistence of the new DAO object management, combines the persistence code and the new DAO object code to create a fragile, closely coupled code. When the persistence code is part of the new DAO object of the company, any changes to this persistent storage requires the persistent code of the new DAO object. This coupling has a negative impact on enterprise new DAO object code maintenance. Below 4, the following is a result of reconstructing improved results using the separation data access object method.

In 15 J2EE mode, each mode acts on certain aspects between design patterns and architectural modes. Each mode is not isolated, and the support of other modes can be more embodied in the meaning of its meaning and use, in order to maximize the mode of use, it is necessary to fully understand the relationship between the mode.

references

System Analyst Tutorial - Rohen Pei, etc.

Design mode: can be used for object-oriented software - Li Yingjun and other translations

Reconstruction - improved the design of existing code - Hou Jie and other translations

J2EE core mode --- 牛志奇 and other translations

UML essence (second edition) --- Xujiafu translated

Contact information:

Email: jingzhou_xu@163.com

Future Studio (Future Studio)

转载请注明原文地址:https://www.9cbs.com/read-2174.html

New Post(0)