The typical Java three layer structure is divided into the representation layer, the middle layer (business logic level) and the data service layer. The three-tier system deals with business rules, data access, and legitimacy checks in the middle tier. Instead of interacting directly with the database, the client establishes a connection to the middle tier through the component and then interacts with the database by the middle tier.
Performance Layer is the traditional JSP technology, since its inception in 1999, after years of development, its wide application and stable performance, as a performance layer of technology has laid a solid foundation.
The Middle layer adopts the popular spring+hibernate, in order to separate the control layer and the business logic layer, it is subdivided into the following several.
Web Tieris the "C" (Controller) in the MVC pattern, which controls the interaction between the business logic layer and the presentation layer, invokes the business logic layer, and returns the business data to the presentation layer for organizational performance, and the MVC framework of the system uses struts.
Service Layer(That is, the business logic layer), responsible for implementing the business logic. The business logic layer is based on the DAO layer, and the business logic required by the system is completed by wrapping the front pattern of DAO components.
DAO Layer, which is responsible for interacting with persisted objects. This layer encapsulates the operation of adding, deleting, checking and changing data.
PO, persisting the object. By mapping the data of the relational database into objects through the Entity Relationship Mapping tool, it is easy to implement the database in object-oriented mode, which uses Hibernate as the ORM framework.
Spring's role spans the entire middle tier, seamlessly consolidating the web layer, service layer, DAO layer, and Po, and its data service layer is used to store data.
A good framework allows developers to mitigate the burden and effort of re-establishing solutions to complex problems; it can be extended for internal customization, and has a strong user community to support it. A framework is usually a good solution to a problem. However, your application is layered, and each layer may need its own framework. Just solving the UI problem does not mean that you have a good coupling between business logic and persistence logic and UI components.
Admittedly, for a simple application, the development efficiency of using ASP or PHP is higher than the development efficiency of the Java EE framework. It may even be felt that this layered structure is more commonly used than
JSP + servlet System development efficiency is also low.
The author from a few angles to explain this problem.
-Development efficiency: Software Engineering is a special industry, different from the traditional industries, such as electrical appliances, construction and automotive industries. Once the products of these industries have been developed, the delivery of users will rarely require subsequent maintenance. But the software industry is different, the late-stage operation and maintenance of software products is a huge project, it is irrational and unfair to consider the development efficiency from the early development time. As we all know, for the traditional ASP and PHP script site technology, the entire site's business logic and performance logic are mixed in the ASP or PHP pages, resulting in a very poor readability of the page, maintainability is very low. Even if you need to simply change the page button, you have to open the page file, risking the risk of destroying the system. However, this problem can be avoided entirely by adopting a strict tiered Java EE architecture. Changes to the presentation layer will never extend the error to the business logic layer, even if an error occurs, without affecting the persistence layer. Therefore, the use of the Java EE layered architecture, even if the early development efficiency is slightly lower, but it is worthwhile.
-Changes in requirements: With the author's years of development experience, few software products need to be completely fixed from the beginning. Customer requirements for software, with the software development process in-depth, and constantly clear up. Therefore, often encountered software development to a certain extent, due to the customer's software requirements have changed, so that the implementation of the software has to change. When the software implementation needs to change, can you keep as many parts of the software as possible, change the implementation of the software as little as possible to meet customer needs changes? The answer is--using an excellent decoupling architecture. This architecture is the layered architecture of the Java EE, in a good layered architecture, the control layer relies on the business logic layer, but not with any specific business logic components, only coupled with the interface, similarly, the business logic layer depends on the DAO layer, and will not be coupled with any specific DAO components, but interface-oriented programming. The software is implemented in this way, even if parts of the software change, and the rest of the parts are not changed as much as possible.
Note: Even in the traditional hardware industry, there are a number of interface specifications. For example, PCI interface, video card or network card, as long as it complies with PCI specifications, you can plug into the motherboard and communicate with the motherboard. As for the internal implementation of this card, not the motherboard is concerned about, this is the benefits of interface-oriented programming. If you need to improve your computer's performance, you need to update the video card, just replace another PCI
interface, instead of discarding the entire computer. If a computer is not a combination of various interfaces, but the whole block, it will mean that even if you only need to update the network card, but also to abandon the entire computer. Similarly, for each component in the software, when a component needs to be refactored, the other components are not affected as much as possible. In fact, this is the ideal situation, even if the most outstanding structure of the present, there will be more or less impact, which is the need for software engineering to improve the area.
Technology updates, System reconfiguration: The software industry's technology updates quickly, although the development of the software industry is unpleasant, but a small range of technical updates particularly fast. Once the change in the objective environment, the need to replace the technology, how to ensure that the system changes the smallest? The answer is to choose a good architecture.
In the traditional model 1 of the program structure, as long as a small demand changes, will mean to abandon the entire page. or rewrite. Although the early development speed is fast, unless it can be guaranteed to never change the structure of the application, otherwise the model 1 structure is not used.
The biggest benefit of using hibernate as a persistence layer technique is that it can be used to analyze and design the system completely in object-oriented way.
The DAO pattern requires the DAO interface to be written for each DAO component, with at least one implementation class, and possibly multiple implementation classes depending on the needs. Replace DAO factory with spring container
In general, the introduction of interfaces inevitably requires the introduction of a factory to be responsible for the generation of DAO components. Spring implements two basic modes: the single-state mode and the factory-mode. With spring, you can avoid using Factory mode entirely, because spring is a very powerful factory. Therefore, it is entirely possible for spring to act as a DAO factory.
When spring serves as a DAO factory, it is not necessary for the programmer to implement the Factory mode by itself, only the DAO component is configured in the Spring container, and the ApplicationContext is responsible for managing the creation of DAO components. With the dependency injection provided by spring, other components do not even have to access the factory, and can use DAO instances directly.
Advantages:
Struts, like Tomcat, turbine and many other Apache projects, is open source software, which is one of its great advantages. Enables developers to gain a deeper understanding of their internal implementation mechanisms. In addition, the advantages of struts are mainly embodied in two aspects: Taglib and page navigation. Taglib is the tag library of struts, which can be used flexibly to greatly improve the development efficiency. In addition, for the current domestic JSP developers, in addition to the use of JSP comes with common tags, rarely develop their own tags, perhaps struts is a good starting point.
About page navigation, I think that will be a future direction of development, in fact, to do so, so that the system's context clearer. Through a configuration file, you can grasp the connection between the parts of the whole system, which is of great benefit to the later maintenance. This is especially true when another group of developers took over the project.
Disadvantages:
Taglib is a great advantage for struts, but for beginners it requires a continuous learning process and even disrupts your web authoring habits, but when you get used to it, you think it's really great.
Struts divides MVC's controller into three, increasing the complexity of the system while gaining a clearer structure.
SSH (struts2+spring3.0+hibernate3) framework (i) theory