Detailed explanation of Java layering concept

Service is the business layer

The action layer acts as the controller

Dao (data access object) data access

1. What is the functional distinction between action layer, service layer, module layer and Dao layer in Java? (the service layer described below is biz)

First of all, this is the most basic layering method now, combined with SSH architecture. The module layer is the entity class of the corresponding database table.

The Dao layer uses hibernate to connect the database and operate the database (add, delete, modify and query).

Service (biz) layer: reference the corresponding DAO database operation, where you can write your own code (such as simple judgment).

Action layer: refers to the corresponding service (biz) layer, where you can jump to the specified page in combination with the struts configuration file. Of course, you can also accept the request data transmitted by the page, or do some calculation processing.

The above hibernate and struts need to be injected into the spring configuration file. Spring connects these into a whole.

Other answers:

Generally, Java is a three-tier architecture: data access layer (DAO), business logic layer (biz or services) and interface layer (UI)

Action is a part of the business layer. It is a manager (master switch) (its function is to take and turn around) (take out the data of the foreground interface, call the biz method, and forward to the next action or page)

Model is generally an entity object (turning real things into objects in Java). Its function is to temporarily store data for persistence (storing in a database or writing to a file). Instead, it encapsulates some data as a package for use in different layers and various Java objects

Dao is the data access layer, which is used to access the database to realize data persistence (permanently save the data in memory to the hard disk). Other answers: action is a controller. Dao mainly does the interactive work of the database. Modle is the model storage. Your entity class biz does the corresponding business logic processing

2. What is the difference between Dao layer and biz layer in Java?

First, explain the general meaning. Service is the business layer and Dao is the data access layer.

Hehe, I've had this problem before. I remember when I first learned programming, I called Dao directly in the service. There was a new Dao class object in the service. I didn't do anything else meaningful, and I don't understand the use of this. After working for a long time, I'll know that business is the top priority in my work.

As we all know, the mainstream programming methods of the standard now adopt the MVC comprehensive design pattern. MVC itself does not belong to the design pattern. It describes a structure and the ultimate goal is to achieve decoupling. Decoupling means that you change one layer of code and will not affect other layers of code. If you know a framework like spring, you will understand interface oriented programming, The presentation layer calls the control layer, the control layer calls the business layer, and the business layer calls the data access layer. At the beginning, it may be a new object to call the next layer. For example, you create a new Dao class object in the business layer and call Dao class methods to access the database. This is wrong, because there should be no specific objects in the business layer, and there can only be references at most. If there are specific objects, they will be coupled. When that object does not exist, I have to modify the business code, which is illogical. For example, the memory on the motherboard is broken. I change the memory. There is no need to change it with the motherboard. I don't need to know where the memory is produced or how large the capacity is. As long as it is memory, it can be plugged into this interface. This is the meaning of MVC. Next, you feel that the meaning of service is not so strict because you do things at different levels, and there are few businesses in a business. For example, you do a paging function, with 1000 pieces of data and 20 pieces in one page. You can write this function as a tool class and package it, and then call the encapsulated method in the business layer, This is what you really do in the business. As long as you don't access the database, you should write it in the business.

If you don't understand, this is a question of experience. Ha ha, in fact, you will understand it in the future. Just at the beginning of writing the code, there was a request. I went to the database to get it. There was almost no business.

Other excellent answers: Bi said that you are now using the SSH framework as a user module:

(1) Suppose that you use the user table and permission table to perform this function, then your foreground page accesses the action, and the action calls the user module service. The user module service determines whether you operate the user table or the permission table. If you operate the user table, the implementation class of the service calls userdao. If the operation is a permission table, the Dao of the permission is called

(2) In other words, Dao must correspond to each table of the database one by one, while service is not. Do you understand? In fact, a project, a service and a Dao can also operate the database, but if there are too many tables and something goes wrong, it will be too troublesome and messy

(3) The advantage is that your whole project is very systematic, consistent with the database table, and has modular functions, so that it is easier to maintain or correct errors in the future, and the performance is higher. Simply put, the Dao layer deals with the database, and the service layer deals with some business processes. As for why you say to use the service layer for encapsulation, I think: Generally speaking, Some business processes of a program need to connect to the database, and some do not need to deal with the database, but directly deal with some business processes. In this way, we need to integrate them into the service, which can play a better role in development and maintenance. At the same time, it is also the embodiment of the model layer function in MVC design pattern

3. What is the action in Java and what is Dao?

The action class is [a class that obtains form data and processes logic]

Dao (data access object) is an interface implementation [obtain the session of operating the database through sessionfactory, and realize some basic deletion, addition and modification of data, so as to realize more practical business operations in the servlet]

4. What is the POJO class?

Plain old Java objects are actually ordinary JavaBeans. POJO names are used to avoid confusion with EJBs, and their abbreviations are relatively direct. There are some classes of attributes and their getter setter methods, which can sometimes be used as value object or dto (data transform object) Of course, it's ok if you have a simple operation attribute, but business methods and methods such as connection are not allowed.

5. What are POJO and VO classes

VO has two versions, one is viewobject and the other is valueobject

Take the former for example. It is only responsible for encapsulating the data transmitted from the page, which is somewhat different from Po

Take struts 1 for example. ActionForm is a typical viewobject Valueobject is the object that saves the value when passing between pages

Generally speaking, Po is the final transfer to Bo and Dao. In many cases, it corresponds to our real database table

The viewobject is the data submitted on a page, which is not necessarily the same as the properties of the Po

Differences between POJO and dto

The abbreviation of object relational mapping. Generally speaking, it is to bind objects to relational databases and use objects to represent relational data.

In the world of O / R mapping, there are two basic and important things to understand, namely VO and po.

VO, value object, Po, persistent object, which are composed of a set of attributes and get and set methods of attributes. Structurally, they are no different. But in its meaning and essence, it is completely different.

1. VO is created with the new keyword and recycled by GC.

Po is created when new data is added to the database and truncated when data in the database is deleted. And it can only survive in one database connection, which will be destroyed when it is disconnected.

2. VO is a value object. To be precise, it is a business object. It lives in the business layer and is used by business logic. Its purpose of survival is to provide a living place for data.

Po is stateful, and each attribute represents its current state. It is an object representation of physical data. Using it, we can decouple our program from physical data, and simplify the conversion between object data and physical data.

3. The attributes of VO vary according to the current business, that is, each of its attributes corresponds to the name of the data required by the current business logic one by one. The attributes of Po correspond to the fields of the database table one by one.

Po object needs to implement serialization interface.

-------------------------------------------------

Po is a persistent object. It is just an object representation of physical data entities. Why do you need it? Because it can simplify our understanding and coupling of physical entities. In short, it can simplify the programming of converting object data into physical data. What is VO? It is a value object. To be exact, it is a business object. It lives in the business layer. It is a business logic that needs to be understood and used. To be simple, it is obtained by conceptual model transformation.

First, let's talk about Po and VO. Their relationship should be independent of each other. A VO can be only part of a PO or composed of multiple Po, It can also be equivalent to a PO (of course, I mean their attributes). Because of this, the Po is independent, and the data persistence layer is independent, and it will not be interfered by any business. Because of this, the business logic layer is also independent, and it will not be affected by the data persistence layer. The business layer only cares about the processing of business logic, and let others know how to store and read it! However, In addition, if we do not use the data persistence layer or hibernate, Po and VO can also be the same thing, although this is not good.

----------------------------------------------------

Java (PO, VO, to, Bo, Dao, POJO) explanation

Po (persistent object)

If there is no o / R mapping, there is no such concept. It usually corresponds to the data model (database) and has some business logic processing. It can be regarded as a Java object mapped to a table in the database. The simplest Po corresponds to a record in a table in the database. Multiple records can use the collection of Po. The PO should not contain any operations on the database.

VO (value object)

It is usually used for data transfer between business layers. Like Po, it only contains data. However, it should be an abstract business object, which can correspond to the table or not, depending on the needs of the business Personally, I think it is the same as dto (data transmission object) and transmitted on the web.

To (transfer object)

Objects transferred between different tie (relationships) in the application

Bo (business object)

From the perspective of business model, see domain objects in UML component domain model. Java objects that encapsulate business logic, and conduct business operations by calling Dao methods in combination with PO and VO.

POJO (plain sequential Java object) is a simple and irregular Java object

Pure traditional Java objects. That is, in some object / relationship mapping tools, the persistent object that can maintain database table records is a pure Java object that conforms to the Java Bean specification without adding other properties and methods. My understanding is that the most basic java bean has only attribute fields and setter and getter methods!.

Dao (data access object)

Is a standard J2EE design pattern of sun. In this pattern, an interface is Dao, which operates in the negative persistence layer. Provide interfaces for the business layer. This object is used to access the database. Usually used in combination with Po, Dao contains various database operation methods. Through its method, combined with Po, it carries out relevant operations on the database. Sandwiched between business logic and database resources. Cooperate with VO to provide crud operation of database

O / R mapper object / Relational Mapping

After defining all mapping, the O / R mapper can help us do a lot of work. Through these mappings, the O / R mapper can generate all SQL statements about saving, deleting and reading objects. We no longer need to write so many lines of dal code.

Entity model

Dal (data access layer)

Idal (interface layer)

Dalfactory

Bll (business logic layer)

BOF business object framework

Service oriented design of SOA Service Oriented Architecture

EMF eclipse model framework

----------------------------------------

Po: the full name is persistent object. The most vivid understanding is that a PO is a record in the database. The advantage is that a record can be treated as an object, which can be easily converted to other objects.

Bo: the full name is business object. The main function is to encapsulate the business logic into an object. This object may include one or more other objects. For example, a resume with educational experience, work experience, social relations, etc.

We can map education experience to a PO, work experience to a PO and social relations to a PO. Create a Bo object corresponding to the resume to process the resume. Each Bo contains these POS. When processing business logic in this way, we can process Bo. VO :

Value object value object

Viewobject presentation layer object

It mainly corresponds to the data objects displayed in the interface. For a web page or an interface of SWT and swing, a VO object is used to correspond to the value of the whole interface. DTO :

Data transfer object

It is mainly used for remote calls and other places where a large number of transmission objects are required.

For example, if a table has 100 fields, the corresponding Po has 100 attributes.

However, as long as 10 fields are displayed on our interface, the client uses the web service to obtain data. It is not necessary to pass the whole Po object to the client. At this time, we can use the dto with only these 10 attributes to pass the results to the client, so that the server table structure will not be exposed After arriving at the client, if this object is used to correspond to the interface display, its identity will be changed to VO at this time

POJO :

Plain sequential Java object is a simple java object. Personally, POJO is the most common and changeable object. It is an intermediate object and the object we most often deal with.

After a POJO is persisted, it is a PO. It is directly used for transmission. In the process of transmission, it is a dto. It is directly used to correspond to the presentation layer, which is vo

DAO:

Data access object

This is the most familiar to everyone, which is the most different from the above o's. There is basically no possibility and necessity of mutual transformation.

It is mainly used to encapsulate the access to the database. POJOs can be persisted into Po, and VO and dto can be assembled with PO

-----------------------------------------------------------------

Po: persistent object, which can be regarded as a Java object mapped to a table in the database. The simplest Po corresponds to a record in a table in the database. Multiple records can use the collection of Po. The PO should not contain any operations on the database

Vo: value object. It is usually used for data transfer between business layers. Like Po, it only contains data. But it should be an abstract business object, which is passed on the web

Dao: data access object, which is used to access the database. Usually used in combination with Po, Dao contains various database operation methods. Through its method, combined with Po, it carries out relevant operations on the database

Bo: business object, Java object that encapsulates business logic, and VO for business operations; POJO: plain ordered Java object is a simple and irregular Java object. Personally, I don't think it is at the same level as other things. VO and PO should belong to it.

---------------------------------------------

Vo: value object, view object

Po: persistent object

Qo: query object

Dao: data access object

Dto: data transfer object

----------------------------------------

ActionForm in struts is a VO;

The entity bean in Hibernate is a PO, also known as POJO;

Criteria in Hibernate is equivalent to a Qo;

When using hibernate, we will define some query methods. These methods are written in the interface and can have different implementation classes And this interface can be said to be a Dao

Personally, I think Qo is similar to dto

----------------------------------------

PO or Bo, the closest layer to the database, is O in ORM, which is basically an attribute in Bo corresponding to the database field. For synchronization and security reasons, it is best to call only Dao or service instead of packcode, backingbean or Bo.

Dao, data access layer, put the objects in VO and backingbean into....

Dto is rarely used. It is basically put into the Dao and only plays a transitional role.

Qo is to put some persistent query operations and statements into..

The basic elements and methods used in VO and V layers are placed therein. If you want to call Bo, you need to convert Bo to VO, and VO to Bo. The advantage of VO is that its page has more element attributes than Bo, which can play a good role....

----------------------------------------

Upstairs, isn't it? Po is a persistent object. Bo = business object - business object.

Po can strictly correspond to database tables, and one table maps to one PO.

Bo is a business logic processing object. My understanding is that it is full of business logic processing and is useful in applications with complex business logic.

Vo: value object, view object, view object

Po: persistent object

Qo: query object

Dao: data access object -- also Dao mode

Dto: data transmission object -- there is also dto mode

summary

The above is all about the detailed explanation of Java layering concept in this article. I hope it will help you understand java. At the same time, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>