DAO pattern in java what is a Business Object

橙三吉。 提交于 2019-12-03 14:17:56

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

René Link

The DAO is responsible for getting a business object in a storage independent way. For example you can create a DAO for accessing a customer like

public interface CustomerDAO {
    public Customer getCustomerById(Integer id)

}

and then implement a data access in jdbc

public class JdbcCustomerDao {

    public Customer getCustomerById(Integer id){
        DataSource dataSource ...;

         Connection con = dataSource.getConnection(...);
    }
}

or implement an CustomerDao that accesses a web service or whatelse. The advantage of the CustomerDao is that a client (the code that uses the CustomerDao) is independent of the concreate storage technology. That's why you should desing the DAO API without storage dependencies. A good hint is the import statements of the CustomerDAO interface. If the CustomerDAO import statements contain something like:

import javax.sql.***

you should re-think the design of your API. But keep in mind that you can also introduce API dependencies with strings. E.g.

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

The business object holds the data an it is the place where you should put the domain logic at. If you are using a rich domain model approach.

For details see Concrete examples on why the 'Anemic Domain Model' is considered an anti-pattern

Fabusuyi012

I'm no expert in this, but I think the layman's explanation I would give to business object is this: business objects hold instance variables and attributes needed for a data access (e.g database) and business logic (for example, a Java class handling real operations) to communicate.

The business object usually does nothing for itself. For example, a phone can be a business object between a person and a news portal, the phone doesn't do anything itself, it just holds the browser and internet configuration settings needed by both parties.

In addition -

When you start implementing all your business classes, I am assuming you already have some couple of DAOs in hand.

Let’s take an example, a blogBO requires blogDAO to create or retrieve an existing blog from the database.

However, a blog contains it’s associated collection of comments. blogBO may have function getComments() that looks into the database using commentBO ( that uses commmentDAO) and reads all comments associated to that blog using that DAO. All these activities belong to business that you are adding in blogBO.

All the underlying DAOs should communicate and returns data to the business layer through TO (transfer object or value object.) However, you should already have an associative value object every of your DAO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!