In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to talk to you about how to achieve J2EE distributed system framework design, many people may not know much about it. In order to make you understand better, the editor summarizes the following content for you. I hope you can get something according to this article.
First, introduction
Framework design (Framework Design) is an important part of system design, and a well-designed framework is the basis of an extensible and changeable (migratory) system. In the following, the author puts forward the author's views and ideas on the framework design aiming at the common J2EE distributed information systems (especially the system in the form of Bhammer S).
(1) problems and solutions
At present, the demand of using J2EE technology to build information system is becoming more and more complex, and the development cycle is becoming more and more urgent. at the same time, the requirements for system stability, expansibility and maintainability are higher and higher. So how to meet the customer's requirements for the system and speed up our development? The information system needs a persistent storage device (such as a database) to store and retrieve information data. When the storage device changes, how can we make the system support the change without rewriting our program code? Can existing code be reused on new systems? Similar problems bring great challenges to our system design.
An effective solution is to separate the information business information according to the application function module: the business logic is separated from the database server, the user interface is separated from the business logic. This is relatively independent, and any change on either side will not affect the other. This is the three-tier concept that we often talk about.
* presentation layer (Presentation)
* Business Logic layer (Business Logic)
* data storage layer (Data)
The presentation layer is responsible for providing the user interface, the business logic layer is responsible for implementing the business logic, and the data storage layer is responsible for the lasting storage of all data in the business logic layer.
The business logic layer has good scalability in the three-tier model. Designers often subdivide the business logic layer further according to the system capacity, distribution, deployment and so on, resulting in multi-layers. This is called n-tier architecture. Therefore, the business logic layer is also the most important part of our system design.
After introducing the three-tier model, we can define a reusable and extensible set of classes according to the characteristics of these three layers, which provides services through the standard API. The process of dividing and defining these class collections is the framework design that we want to elaborate.
(II) definition and characteristics of the framework
What is a framework? The framework can be defined as a set of extensible and reusable subsystems of relational services. Common software frameworks are: MFC, VCL, JDK and so on. It has the following characteristics.
* it is a collection of functional classes that can cooperate with each other to provide services to the business logic subsystem.
* it contains concrete classes and abstract classes that define standard interfaces, interactions between objects, and system-related constants. Abstract classes, which can contain both abstract and concrete methods.
* in order to leverage, customize, or extend the services of a framework, it is usually necessary for the consumer of the framework to define subclasses of existing framework classes.
* the defined classes in the framework are only provided to the user-defined class calls, but never the user-defined classes.
Second, frame design
For a distributed information system, we introduce a three-tier design model through the above discussion, and now we can design the framework of the system on this model. However, make clear the goals of the framework design before you start the design. According to the system requirements and framework definition, our goals are:
* maximize reuse of classes (components, code).
* the framework structure is as reasonable, simple and clear as possible.
* the framework should be flexible and scalable. Meet the secondary development requirements of users.
* the framework should be secure, stable, efficient, maintainable and upgradeable.
* there should be no bi-directional dependency between the sub-systems (packages) of the framework.
The type (Classes-Type) architecture diagram of system classes in the three-tier design model of distributed information systems is shown below:
Figure (1)
So this framework is designed to:
The framework of distributed information system is divided into four main packages: user interface package (ui) of presentation layer, business object package (bs) of business logic layer, data persistence package (ps) of data persistence layer, general utility package of system resource layer (su). Combined with the company's own naming conventions, the specific UML framework diagram can be shown as follows:
Figure (2)
Among them, "ProjectName" is the English name for the establishment of the information system project, such as: state-owned assets management system, "ProjectName" is "sams"; "CompanyName" is the company's English abbreviation, such as: Yotuo system integration, "CompanyName" is "auto".
"ui"-user interface pack (User Interface).
"bs"-Business Logic package (Business Session).
"ps"-data persistence package (Persistence Store).
"su"-system general utility package (System Utility).
The framework implementation of each layer package will be discussed in detail in combination with the J2EE architecture.
(1) Design of general system resource layer framework
The general system resource layer framework design is the design of the system general package su (System Utility) from the point of view of the framework we defined above. As you can see from figure 2, the ui package, the BS package, and the ps package all call interfaces from the su package, and the su package provides services to them. Therefore, the design of this layer framework is the basis of whether the system can achieve class (component) reuse, and the key to whether the system can meet the requirements of reliability, stability, high efficiency and maintainability.
Since it is a general-purpose package, what services (or tools) does it provide? We know that many standard services are provided in the J2EE architecture, such as JMS, EJB, JTA, and so on. So should su packages provide similar services? There is no unified answer to these questions, which mainly depends on the project system analysis and designers according to the characteristics and needs of the project, what kind of technology is applied and what kind of design ideas and design patterns are used to solve the problem.
It is worth mentioning that "the frame is the skeleton and the design pattern is meat". The idea of design pattern affects the composition of the framework, and the application of appropriate design patterns in a framework is where the essence of the framework lies. In this layer, the design patterns commonly used are: structural Bridge pattern, Facade, Proxy; creation Factory, Singleton and behavioral Strategy and so on.
According to the author's experience, combined with the application of J2EE architecture, the framework of the general system resource layer can be:
Figure (3)
Figure (3) is illustrated as follows:
The su package contains 8 subpackages, which are:
(1), resource package, which contains classes for standard interfaces to access J2EE middleware (application server) resources. For example, the JNDI service of the container, etc.
(2) the factory package, which contains classes that create interfaces for different types of objects, is designed to help control class creation and reduce the risk of misuse of some key objects.
(3), the jms package, which wraps classes about applying J2EE message services.
(4) ui package, which encapsulates some standard common classes for the presentation layer.
(5), ejb package, referencing Bridge design pattern, adding one more layer of encapsulation in EJB, generally convenient to expand and maintain EJB in the future, and reduce the risk of ejb programming. According to the type of ejb, it is divided into two subpackages: session and entity.
(6) the db package contains classes about accessing the database, including standard interfaces such as database connection pooling, reports, and serial numbers.
(7), log package, which contains interface classes for recording system logs and debugging applications. Subdivide the applog and appdebug packages.
(8), exception package, according to the characteristics of the system, customize a set of application exceptions.
(9) tools package, which contains common standard system function classes. According to the type of these functions, they are divided into four packages: date, maths, format and constfunc.
The above framework is for reference only, designers can redefine it according to their own actual needs.
(2) presentation layer framework design
The presentation layer framework design corresponds to the ui package framework design we defined. When designing for J2EE architecture, MVC (Model-View-Controller) design pattern is often applied. The MVC pattern decomposes the application according to its role, and then uses different methods to solve it.
* Model, the model, the specific data model of the system application, does not care about how to express and when to access. Only consider the integrity and storage of the data. It corresponds to the data persistence layer, so it is the concern of our data persistence layer framework design.
* View, view, is only a matter of how to represent it. This level of discussion.
* Controller, controller, controller is to solve the problem of when to access. It is the business logic of the system application, which determines whether certain conditions are met before the application can access the specific data in the model (Model), and then delegate the specific data obtained to the view responsible for presentation (View) according to the situation. Corresponding to the business logic layer, it is discussed in the design of the business logic layer framework.
In the J2EE architecture, AWT, SWING, JSP, and Servlet are all designed for presentation (views). In practical application, we often write JSP and APP client applications according to different functional modules of the system to interact with users, so the framework definition can be divided into two packages, jsp package and app package; at the same time, sometimes we also need to define some system constants and deal with some page logic, so we also define a vbn (view bean) package to store these page classes and constant classes. So the framework design of the presentation layer can be:
Figure (4)
Figure (4) is illustrated as follows:
(1) jsp package, which stores jsp program files according to different functional modules of the information system. Since the jsp file type is not a java file type, this package can be treated as a directory, proposed, and placed separately in a reasonable directory according to the requirements of the system deployment. Among them, JFunctionModule1, JfunctionModule2, JfunctionModule3 and other names are the specific functional module names of the information system. Directories can be defined and arranged as needed.
(2) app package, which stores java client applications. Among them, AFunctionModule1, AfunctionModule2, AfunctionModule3 and other package names are the specific function module package names of the information system. According to the ownership of the client application, it is stored in a specific functional module package.
(3) vbn package, which stores constant definition classes and page processing classes in the presentation layer of the information system.
Finally, it is worth mentioning that in the development of jsp pages in the presentation layer, in order to avoid writing too much code and logic in the same page number, and to improve the efficiency and maintainability of jsp programs, we can apply the VC (View-Controller) design pattern, html as the view and servlet as the controller. Of course, it can also be implemented using struts technology, which is not discussed here. This should be a specific programming problem.
(3) Design of business logic layer framework
The business logic layer design corresponds to the framework design in which we define the bs package. It is the Controller (controller) of MVC mode, which is responsible for accessing the data persistence layer and submitting the returned data to the presentation layer, acting as a connecting link between the preceding and the following. In J2EE architecture, we generally apply session Bean to implement.
The business logic layer design is the most complex and heavy workload in the detailed design of the system design. It is necessary to extract the use case (Use Case) of each functional module of the information system from the system analysis, and then use UML language to draw the sequence diagram (or collaboration diagram) of the use case in detail for each use case, and then decide whether to use stateful or stateless session Bean according to the actual situation. However, the design of the framework for this layer is simple and straightforward, and the framework can be:
Figure (5)
Under the bs package, the subpackage is defined directly according to the name of the functional module of the information system. Where bsFunctionModule is the English name of the functional module.
(4) Design of data persistence layer framework
Data persistence layer corresponds to Model in MVC design model. Its design is the most important part of information system design and the basis of system performance and translation. Its design quality directly affects the success of the project. The framework design of data persistence layer can be better outlined only after the design of data model is discussed in detail. Therefore, this section intends to explore the persistent data model design, and then implement its framework design.
◆ common data persistence layer design types
(a) use SQL code directly in the classes in the business logic layer. As shown in the following figure:
Figure (6)
* advantages:
It is very efficient to write code.
* disadvantages:
SQL code appears everywhere in the program's classes; the logical business class is directly coupled to the database, which means that any small change will lead to a change in the program's original code.
* conclusion:
It is feasible for small applications, but for enterprise systems, this method of writing dead SQL in logical business classes can make the code difficult to maintain and extend.
(B) SQL code is encapsulated in one or more data proxy classes. As shown in the following figure:
Figure (7)
* advantages:
Adding an additional layer of encapsulation between the business class and the database greatly improves the maintainability of the system. This approach includes strategies that can take advantage of database stored procedures, SQLJ, and Microsoft ADO data access.
* disadvantages:
Any change to the database will directly affect the code of the data agent, that is, the original code of the program must be changed.
(C) without writing SQL code, the access to the database is realized entirely through the robust data persistence layer. As shown in the figure:
Figure (8)
The so-called robust data persistence layer must meet at least the following conditions:
(1) to support the advanced features of relational databases. (e. G. transactions, stored procedures, cursors)
(2) the mapping between objects and relationships is supported, and users do not interact with the database directly with SQL.
(3) support multiple connections and database connection pooling.
(4) it supports multiple architectures and databases of different vendors.
* advantages:
Application developers do not need to know the database structure or even how objects are stored in the database. It is helpful for organizations to develop large-scale information systems for critical business. The system has good transplanting, maintainability and expansibility.
* disadvantages:
Because the access to the database is handed over to the persistence layer, it has some impact on the performance of the system in theory.
Specific selection of ◆
Several common types of data persistence layer are listed above, so which type is more appropriate for us to apply? This needs to be decided according to the size of the system and the specific circumstances of its needs. In order to develop a system in J2EE architecture, we should choose (B) and (C) two data persistence layers.
In J2EE architecture, type (C) robust data persistence layer can be implemented by EJB container management entity Bean (CMP). In EJB2.X, CMP is a standard specification for implementing robust data persistence layer. Developers do not have to write SQL code in CMP, and all interactions with the database are left to the EJB container. Because J2EE is an open, standard specification, CMP components can be portable between EJB containers and databases.
In the actual information system development process, we often need to deal with some complex queries or reports, and these query data often come from multiple data tables, and the entity objects of the query results are not conceptual. At this time, it seems a little powerless for us to encapsulate it with CMP. Because in theory, the entity Bean represents a row of data in a database table after all.
In this case, it is more appropriate to design the data persistence layer with type (B). We can use EJB's stateless session Bean to implement this layer of encapsulation. It is common to use Bridge design patterns to achieve:
(1) establish data access object DAO (Data Access Object) interface. Define the abstract operation behavior of the data source, and provide a standard API structure that facilitates access and maintenance of the data.
(2) implement the data access object interface. DAOImplementor . According to the content of the specific DAO interface, depending on the type of data source applied, there can be implementations for multiple data sources (such as DAOImplementorSQLServer,DAOImplentorOracle, etc.). Then apply the Adapter design pattern to assign a specific data source-driven interface to the DAO.
(3) establish EJB to call DAOImplementor to realize business logic.
As shown in the following figure:
Figure (9)
◆ framework design
Through the above discussion, the framework of our data persistence layer (ps) package can be:
Figure (10)
The ps package is divided into subpackages according to the functional modules of the information system (for example, the figure above is divided into three functional module packages, PfunctionModule1, PfunctionModule2 and PfunctionModule3), and each functional module package is subdivided into:
Be (business entity) package, which contains business entity objects (database relational mapping objects), DAO definition interfaces, and so on.
The eb (entity bean) package contains entity components that implement the data persistence layer.
The sb (session bean) package contains session components that implement the data persistence layer.
Third, Overview
System framework design is not immutable, often according to the system designer's views on a certain information system, the framework is also different. However, in order to design a good framework, in addition to having a clear design goal, the key lies in the need to investigate and study the status and related technical characteristics of similar products in the system, to understand the current popular technology to provide theoretical and technical support for this product, combined with the characteristics of their own products, can gradually outline the framework blueprint of the whole product project.
After reading the above, do you have any further understanding of how to implement the J2EE distributed system framework design? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.