Java hierarchical service/action/DAO summary

Source: Internet
Author: User
Tags abstract ssh advantage

Java layering


Service is the business layer

The action layer acts as the controller.

DAO (Data Access Object) Data Access

 

1. What are the functional differences between the Action layer, Service layer, modle layer, and Dao layer in JAVA? (The service layer described below is biz)


First of all, this is the most basic layering method, combining the SSH architecture. The modle layer is the entity class of the corresponding database table.

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

Service (biz) layer: reference the corresponding Dao database operations, where you can write the code you need (such as simple judgment ).

Action layer: reference the corresponding Service (biz) layer. Here, combined with the Struts configuration file, you can jump to the specified page. Of course, you can also accept the request data transmitted by the page and perform some computation.

The above Hibernate and Struts must all be injected into the Spring configuration file. Spring makes these connections a whole.

 
Other answers:
Generally, java is a three-tier architecture data access layer (dao) business logic layer (biz or services) interface layer (ui)
Action is a part of the business layer and is a manager (master switch) (used to retrieve the data in the foreground interface, call the biz method, and forward the data to the next action or page)
Model creation is generally an entity object (turning a real thing into an object in java). It stores data temporarily for persistence (stored in a database or written into a file) instead, it encapsulates some data as a package to be used in different layers and various java objects.
Dao is the data access layer used to access the database for data persistence (store the data in the memory permanently to the hard disk. Other answers:
Action is a controller Dao mainly used for database interaction. Modle is used to store your entity class Biz in the model for corresponding business logic processing.

2. What is the difference between the dao layer and the biz layer in java?
First, the service is the business layer, and dao is the data access layer.
Well, I have had this problem. I remember that when I first learned programming, I called dao directly in the service, and a new dao class object was called in the service, other meaningful things have not been done, and you do not know how to use them. After you have been working for a long time, you will know that the business is the top priority in your work.
As we all know, the mainstream standard programming methods are all using the MVC integrated design model. MVC itself is not a design model. It describes a structure to achieve decoupling, decoupling means that you change a certain layer of code without affecting other layers of code. If you have a framework like spring, you will understand interface-oriented programming and the presentation layer calls the control layer, the control layer calls the business layer and the business layer calls the data access layer. In the early stage, new objects may call the next layer. For example, if you call a DAO class object on the business layer to access the database, it is wrong to write the method, because the business layer should not contain specific objects, but can only have references at most. If a specific object exists, it is coupled. When the object does not exist, I need to modify the business code. This is not logical. For example, if the memory on the motherboard is broken, I need to change the memory instead of the motherboard. I don't need to know which memory is produced or how large the memory is. As long as the memory is used, I can use this interface. This is the meaning of MVC. Next, let's talk about the meaning of the service. In fact, because you are not so strict in the hierarchy of things, there are only a few things in your business. Here is the simplest example, you create a paging function with 1000 pieces of data and 20 pieces of data on one page. You can encapsulate this function as a tool class and then call this encapsulated method at the business layer, this is what is really done in the business, as long as the database is not accessed, it must be written in the business.
Ask questions that you don't understand. This is an issue of experience. I just wrote the code with a request, and I went to the database to fetch it, and there was almost no business.


Other excellent answers:
For example, you are using the SSH framework to create a user module:
(1) assume that the user table and permission table are used for this function, then you can access the action on the front-end page and then call the service of the user module, the user module service determines whether you operate the user table or permission table. If you operate the user table, the service implementation class calls userDAO. If the permission table is operated, the DAO of the permission is called.
(2) DAO must correspond to each table in the database one by one, while service is not. Do you understand? In fact, you can operate databases in the same way as a service in a project and a DAO,

But if there are a lot of tables and there is a problem, it will be a lot of trouble and it will be too messy.

(3) The advantage is that your entire project is very systematic, consistent with the database table, and the function is modular. In this way, it is easier to maintain or correct the error in the future, and the performance is also higher.
Simply put, the DAO layer deals with databases, and the service layer handles some business processes,
As to why you want to use the service layer encapsulation, I think: in general, 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, in this way, we need to integrate it into the service, which can play a better role in development and maintenance, and also reflect the model layer function in the MVC design mode.


3. What is action in java and DAO?
The Action class is [class for obtaining Form data and processing logic]
DAO (Data Access Object) is an interface implementation [getting database operation sessions through SessionFactory, and implementing some basic deletion, adding, and modifying Data to make business operations more operational in servlet]
 
4. What is a Pojo class?
A simple Java Object (Plain Old Java Objects) is actually a common JavaBeans. The POJO name is used to avoid confusion with EJB, and the abbreviation is direct. some attributes and their getter setter methods can be used as value object or dto (Data Transform Object. of course, if you have a simple operation attribute, you can do the same, but you cannot have business methods or methods such as connection.

 

5. What are the pojo and vo classes?
Vo has two arguments: viewObject and valueObject ..

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

Taking struts1 as an example, ActionForm is a typical viewObject. valueObject is the object that saves the value when the page is transferred between the page ....

In general, PO is what is finally passed to BO and BO to transmit DAO. In many cases, PO corresponds to our real database tables.

ViewObject is the data submitted on a page, which is not necessarily the same as the property of the PO ....
 
Difference between pojo and DTO

The abbreviation of rational ING. In layman's terms, it is to bind an object to a relational database and use an object to represent relational data.
In the O/R Mapping world, there are two basic and important things to understand: VO and PO.
VO, Value Object, PO, and Persisent Object are composed of get and set methods of a group of attributes and attributes. In terms of structure, they are nothing different. But in essence, it is completely different.

1. VO is created with the new keyword and collected by GC.
PO is created when new data is added to the database, and deleted when data in the database is deleted. In addition, it can only survive in one database connection and will be destroyed if the connection is closed.

2. VO is a value object. Specifically, VO is a business object that is used by the business logic and survive at the business layer. It aims to provide a place for data to survive.
PO is stateful, and each attribute represents its current state. It is the object representation of physical data. Using it can decouple our programs from physical data and simplify the conversion between object data and physical data.

3. The VO attributes vary according to the current business. That is to say, each of its attributes corresponds to the names of the data required by the current business logic.
PO attributes correspond to the fields in the database table one by one.

The PO object must implement the serialization interface.
-------------------------------------------------

PO is a persistent object. It only represents an object of a physical data entity. Why does it need it? It simplifies our understanding and coupling of physical entities, and simplifies the programming of converting object data to physical data. What is VO? It is a value object. To be precise, it is a business object that lives on the business layer. It is something that needs to be understood and used by the business logic, it is obtained by converting the conceptual model.
First, let's talk about PO and VO. Their relationship should be independent of each other. a vo can be only a part of PO or composed of multiple PO, it can also be equivalent to a PO (of course I mean their attributes ). As a result, the PO is independent, and the data persistence layer is independent, so it is not subject to any business interference. In this case, the business logic layer is also independent and will not be affected by the data persistence layer. The business layer only cares about the processing of the business logic. As for how to read and give it to others! However, if we do not use the data persistence layer or hibernate, PO and VO can be the same thing, although this is not good.

----------------------------------------------------
Java (PO, VO, TO, BO, DAO, POJO) explanation
 
PO (persistant object) Persistent object
The concept that appears during o/r Ing. If there is no o/r ING, this concept does not exist. Usually it corresponds to the data model (database), and some business logic is processed. It can be viewed as a java object mapped to a table in the database. The simplest PO is to correspond to a record in a table in the database. A set of PO can be used for multiple records. The PO should not contain any operations on the database.

VO (value object) value object
It is usually used for data transmission between business layers. Like PO, it only contains data. However, it should be an abstract business object, which can correspond to a table or not. This is based on the business needs. I personally think it is the same as DTO (data transmission object) and transmitted on the web.

TO (Transfer Object), a data transmission Object
Objects transmitted between different tie (links) of an application

BO (business object) business object
From the business model perspective, see the domain objects in the UML component domain model. Java objects that encapsulate the business logic, and perform business operations by calling the DAO method and combining PO and VO.

POJO (plain ordinary java object) simple and rule-free java object
Pure traditional java objects. In other words, in some Object/Relation Mapping tools, the persisent object that can maintain database table records is a pure Java Object that complies with Java Bean specifications, without adding other attributes and methods. My understanding is the most basic Java Bean, only the attribute fields and the setter and getter methods !.

DAO (data access object) data access object
Is a standard j2ee Design mode of sun. There is an interface in this mode that is DAO, and its operation on the negative persistence layer. Provides interfaces for the business layer. This object is used to access the database. It is usually used in combination with PO. DAO contains various database operation methods. It combines PO with other methods to perform database operations. Stored in the middle of the business logic and database resources. Works with VO to provide database CRUD operations...

O/R Mapper object/relationship ing
After all mapping is defined, this O/R Mapper can help us do a lot of work. Through these mappings, this 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
SOA Service Orient Architecture Service-oriented design
EMF Eclipse Model Framework Eclipse Modeling Framework

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

PO: full name is
Persistant object persistent object
A po is a record in the database.
The advantage is that a record can be processed as an object, which can be easily converted to other objects.

BO: Full name:
Business object: business object
The main function is to encapsulate the business logic as an object. This object can include one or more other objects.
For example, a resume includes educational experience, work experience, social relationship, and so on.
We can correspond an educational experience to a PO, a work experience to a PO, and a social relationship to a PO.
Create a BO object to process the resume. Each BO contains the PO.
In this way, we can process the business logic for BO.

VO:
Value object
ViewObject presentation layer object
It mainly corresponds to the data objects displayed on the interface. For a WEB page, or a SWT or SWING interface, use a VO object to correspond to the value of the entire interface.

DTO:
Data Transfer Object
It is mainly used for remote calls and other places where a large number of objects need to be transferred.
For example, if a table has 100 fields, the corresponding PO has 100 attributes.
However, we only need to display 10 fields on the interface,
The client uses WEB service to obtain data. It is not necessary to pass the entire PO object to the client,
In this case, we can use DTO with only these 10 attributes to pass the results to the client, so that the server table structure will not be exposed. after the client is reached, if this object is used for display on the corresponding interface, then its identity will be changed to VO

POJO:
Plain ordinary java object simple java object
I personally think that POJO is the most common and variable object. It is an intermediate object and the most common object to deal.

After a POJO is persisted, it is the PO
It is DTO in the process of passing and passing.
Directly used to correspond to the presentation layer is VO

DAO:
Data access object
This person is the most familiar with it. It is the most different from the previous O, and there is basically no possibility or need to convert each other.
It is mainly used to encapsulate access to the database. With POJO, POJO can be persistently converted into PO, and PO can be assembled into VO and DTO.

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

PO: persistant object persistent object, which can be considered as a java object mapped to a table in the database. The simplest PO is to correspond to a record in a table in the database. A set of PO can be used for multiple records. The PO should not contain any database operations.
        
VO: value object. It is usually used for data transmission between business layers. Like PO, it only contains data. However, it should be an abstract business object, which can correspond to a table or not. This is based on the business needs. I personally think it is the same as DTO (data transmission object) and transmitted on the web.

DAO: data access object: The data access object used to access the database. It is usually used in combination with PO. DAO contains various database operation methods. It combines PO with other methods to perform database operations.

BO: business object. It encapsulates java objects of business logic. It calls DAO method and uses PO and VO to perform business operations;

POJO: plain ordinary java object is a simple and non-rule java object. I personally think it and others are not at the same level. VO and PO should both belong to it.

---------------------------------------------
VO: value object and view object
PO: Persistent Object
QO: query object
DAO: Data Access Object
DTO: data transmission object
----------------------------------------
The ActionForm in struts is a VO;
The Entity bean in hibernate is a PO, also called POJO;
The Criteria in hibernate is equivalent to a QO;
When using hibernate, we will define some query methods. These methods can be written in interfaces and have different implementation classes. This interface can be called DAO.
I personally think that QO is similar to DTO.
----------------------------------------
PO is also called BO. The closest layer to the database is the O in the ORM. It is basically an attribute corresponding to the database field in the BO. For the sake of synchronization and security, it is best to only call DAO or Service, instead of using packcode, backingBean, or BO.
DAO, data access layer, put objects in VO and backingBean ....
DTO is rarely used. It is basically put into DAO, but serves as a transitional function.
QO puts some query operations and statements with durability ..
Basic elements and methods used in VO and V layers are included. 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 very good role ....
-----------------------------------------
Wrong upstairs, PO is a persistent object. BO = business object-business object.
A po can correspond to a database table strictly, and a table is mapped to a PO.
BO is the object of business logic processing. My understanding is that it is full of business logic processing and is useful in complicated business logic applications.
VO: value object and view object
PO: Persistent Object
QO: query object
DAO: Data Access Object-there is also the DAO mode
DTO: data transmission object-also has the DTO mode


Java layered summary

I. Why do we need to layer data.

In the past, when we were writing code, we all encountered an error in the main () method, so we could debug it slowly, which wasted a long time, our programmer's time is very valuable.

But when we use a layered architecture, we can clearly know where the error is, or in the company, we basically use a layered architecture, because it can separate our programmers

More concise.

2. What are the benefits of layering.

In fact, it has brought a lot of benefits. First, we will not talk about the convenience of maintenance and separation of concerns.

1. Easy to change or replace.

Let's talk about the ease of replacement or update. The current database I use is an SQLServer Database. If I need

Replace the database with MySQL. If the syntaxes for addition, deletion, modification, and query are the same, we only need to change the connection string of the BaseDao tool class without changing the code of other layers.

2. Decoupling between software is realized.

That is, each part changes independently. To give a simple example, draw a triangle and draw a text. In DX and OpenGL, we use a completely different method (not just the function name ).

But on which day did you find that you love to use DX or OpenGL, which does not affect how you draw triangles, text, or photos, so what you draw is decoupled from what you draw.

This decoupling method inserts an interface in the middle.

Confucius said that all software problems can be solved by adding an interface. The larger your team, the faster the demand changes. The more you want to ensure that there are fewer dependencies between programmers,

The better the decoupling of your software, the more interfaces you have, the more complex the relationship (different from chaos). The easier it is to cope with changes, the more money you earn, and the more stable it is.

3. Improve the reuse of software components

In software development, due to different environment and functional requirements, we can maintain overall stability and adapt to new requirements through local modification and restructuring of mature software systems in the past.

Such software is called the chong software.

III. Layered architecture and analysis.

It can be roughly divided:

 


DAO: this layer is divided into interfaces and its implementation classes to implement functions. dao sub-directories only provide external interfaces, and its implementation class should be placed in the data access layer, that is, the impl layer.

DTO:

Data Transfer Object
It is mainly used for remote calls and other places where a large number of objects need to be transferred.
For example, if a table has 100 fields, the corresponding PO has 100 attributes.
However, we only need to display 10 fields on the interface,
The client uses WEB service to obtain data. It is not necessary to pass the entire PO object to the client,
In this case, we can use DTO with only these 10 attributes to pass the results to the client, so that the server table structure will not be exposed.

After the client is reached, if this object is used for display on the corresponding interface, then its identity will be changed to VO

Differences between DAO and DTO:

DAO: Data Access Object-there is also the DAO mode
DTO: data transmission object-also has the DTO mode

BIZ: business logic layer. Like dao layer, only common interfaces are provided.

Model: the entity layer for reading and retrieving data.

JavaBian: javaBean is a model or model layer in the MVC design model. In general programs, we call it a data layer, which is used to set data attributes and some behaviors, then, I will provide the get/set method for obtaining and setting attributes.

 

 

Servlet: used to interact with JSP pages

POJO :( plain ordinary java object) simple and non-rule java object pure traditional java object. That is to say, in some Object/Relation Mapping tools, persisent that can maintain database table records

An object is a pure Java object that complies with the Java Bean specifications without adding other attributes and methods. My understanding is the most basic Java Bean, only the attribute fields and the setter and getter methods !.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.