java write code in a layered architecture

Before people write code, written in the main () method, if something goes wrong, slowly debugging, this will waste a lot of time debugging, and the programmer's time is very valuable. But when using a layered architecture, errors in the system when you can clear the error to know what went wrong, and now the company is using a layered architecture hundred percent, because that can be separated Follow us programmers make the code more concise.

The benefits of a layered architecture

In fact, layered architecture brings many benefits, starting with easy maintenance and separation of concerns, it has already been mentioned.

Easy to change or replace

Let us talk about easy to replace or update, for example, I am using the database is a SQL Server database, if I need to replace the database MySQL, in the case of additions and deletions consistent syntax change under investigation, we only need to change the connection string of tools BaseDao without having to change the code of other layers.

Decoupling between software

After decoupling, each part can be varied independently.

As a simple example, draw a triangle and a draw text, DX and OpenGL in the following different approach is used (not only the function names are not the same). But you one day you find that you love to use DX or OpenGL, does not affect how you draw a triangle or text, what love painting painted what, then you draw something now means you draw on decoupled. This particular approach decoupling layer is interposed in an interface (interface). All software problem can be solved by adding a layer interface. The larger your team, the faster the changes in demand, the more you want to ensure that fewer dependencies between programmers, software you decouple the better, the more the interface, the more complex relationships (not the same as with the chaos) , the easier it is to cope with change, the more money, the more stable.

Do to improve the reuse of software components

In software development, due to the different environments and functional requirements, we can mature software systems of the past, partial modification and restructuring, maintaining the overall stability, in order to meet the new requirements. Such software is called reusable software.

Layered architecture and resolve

It can be roughly classified into hierarchical codes:

 

DAO (Data Access Object): This layer is divided into the interface and implementation class to implement his functions, dao subdirectory only provides external interfaces, and his implementation class to put the data access layer, is impl layer.

DTO (Data Transfer Object, Data Transfer Objects): mainly used for local transport objects requires a lot of long-distance calls and so on. For example, we have 100 fields in a table, then the corresponding PO have 100 properties. But as long as we show 10 fields on the interface, the client with WEB Service to obtain the data, there is no need to pass the entire PO object to the client, then we will be able to deliver results to the client with only the ten DTO attributes, this also does not expose the server table structure. After reaching the client, if this object to the corresponding screen display, that at this time it's turned on the identity of VO.

BIZ (business logic layer): with dao layer only as the interface.

Model (physical layer): for reading, the data fetch.

JavaBean: javaBean in the MVC design model model, also known as the model layer, in the general program, we call it the data layer, it is used to set the properties and behavior of some data, and then I will provide property get and set properties get / set methods.

Servlet: used to interact with the JSP page.

POJO (P Lain Ordinary Java Object , no simple rule of Java objects) : traditional Java object. Java object that is, in some Object / Relation Mapping tool, able to do maintenance of the database table records Persisent Object is entirely consistent with a Java Bean specification, no increase in other properties and methods. My understanding is that the most basic Java Bean, only attribute fields and getter and setter methods. 

 

"Your temperament, the way you walk hidden, read the book and loved the people."

Guess you like

Origin www.cnblogs.com/yanggb/p/11868013.html