DAO structure in Java, what is a business object

Directly from this oracle article about the J2EE DAO Pattern:

Everything is really very clear, but the business object is "member" (as they call it).

Here I will give a quote that I would like to know more about (an example from real life is especially useful (easy)).

Businessobject

BusinessObject represents a data client. This is an object that requires access to a data source to receive and store data. A BusinessObject can be implemented as a session bean, an object bean, or some other Java object in addition to a servlet or helper bean that accesses a data source.

I am trying to use this template as an exercise (as a student in the OCPJP exam, an understanding of the DAO template is required). So far, I have my DataSource (mysql database), my transfer object (JavaBean named Person) and my DAO object that interacts correctly between the database and JavaBean (Person).

So again What is a business object?

thank you in advance

+6
source share
4 answers

Business objects are objects that concentrate all the logic of your application. Use Business Objects to separate business data and logic using an object model.

SEE HERE

+5
source

The DAO is responsible for obtaining the business object in a storage-independent manner. For example, you can create a DAO to access the client, for example

 public interface CustomerDAO { public Customer getCustomerById(Integer id) } 

and then implement data access in jdbc

 public class JdbcCustomerDao { public Customer getCustomerById(Integer id){ DataSource dataSource ...; Connection con = dataSource.getConnection(...); } } 

or implement a CustomerDao that accesses a web service or something. CustomerDao's advantage is that the customer (the code that CustomerDao uses) is independent of nodule storage technology. This is why you should access the DAO API without dependencies between repositories. Good advice is the import statements of the CustomerDAO interface. If the CustomerDAO import statements contain something like:

 import javax.sql.*** 

You should consider designing your API. But keep in mind that you can also introduce API dependencies with strings. For instance.

 public Customer findCustomer(String sqlWhereClause){ ... } 

The business object stores the data, and this is the place where you should put the domain logic in. If you are using a wealthy model approach.

See more specific examples of why the “Anemic Domain Model” is considered an anti-pattern.

+3
source

I am not an expert in this, but I think that the layman’s explanation for the business object would be as follows: the business objects contain the instance variables and attributes needed to access the data (for example, the database) and business logic (for example , a Java class that handles real operations) for communication.

A business object usually does nothing for itself. For example, a phone can be a business object between a person and a news portal, a phone does nothing by itself, it just contains browser settings and Internet configurations needed by both parties.

0
source

Besides -

When you start implementing all your business classes, I assume that you already have a couple of DAOs.

Let's take an example: blogBO requires blogDAO to create or retrieve an existing blog from the database.

However, the blog contains a related collection of comments. BlogBO can have a getComments () function that scans the database using commentBO (which uses commmentDAO) and reads all comments related to this blog using this DAO. All these actions belong to the business that you add to blogBO.

All basic DAOs must exchange data and return data to the business layer through TO (transfer object or value object). However, you should already have an associative value object for each of your DAOs.

0
source

Source: https://habr.com/ru/post/1485273/


All Articles