Results 1 to 10 of 10

Thread: Should Business Objects have References to DAOs?

Threaded View

  1. #1
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default Should Business Objects have References to DAOs?

    Hello,

    Follow a successful previous thread, I'd like to open a new thread. In the <a href="http://forum.springframework.org/showthread.php?t=9846">previous architectural thread</a>, we talked about what it means to move business logic into business objects, where business objects are brought to life by Hibernate, but wired by Spring.

    I've got a use case that illustrates the need for the business object to have a reference to DAOs. Due to how Hibernate manages certain relationships, some business logic operations need the DAOs. I will illustrate this use case below.

    My question is: How common is it to have Business Objects that contain DAOs? In the previous thread, we acknowledged that business objects, in order to perform business logic, need dependency injection. Here I ask: should we give DAOs to Business Objects?

    Use Case:

    A car detail shop needs to upgrade the wheels on a car. The old wheels are thrown away, and the new wheels are installed.

    Business Objects:

    Car, 1:Many Wheel
    DetailShop

    Methods:

    Code:
    DetailShop.upgradeWheels(Car, Wheel[] newWheels)
    or
    Code:
    Car.upgrade(Wheel[] wheels)
    Because Hibernate will not delete objects out of persistence if an object has its reference removed, we need to managed the deletion of old objects out of persistence manually.

    Car.upgrade() will look like this:

    Code:
    public void upgrade(Wheel[] newWheels) {
        Wheel[] oldWheels = getWheels();
        for (int i = 0; i < oldWheels.length; i++) {
            wheelDAO.delete(oldWheels[i]);
        }
        setWheels(newWheels);
    }
    If we were to just call
    Code:
    setWheels(newWheels)
    , the old wheels would never get deleted from the database.

    This also seems like it breaks encapsulation, since now these methods need to know the persistence details, but this is besides the point.

    What do others think? Does this approach make sense? Should Business Objects require DAOs to function? Obviously, someone needs to call dao.delete().

    As always, your thoughts and opinions are much appreciated!
    Seth
    Last edited by Rod Johnson; Jan 18th, 2006 at 10:19 AM.

Similar Threads

  1. Spring-based architectural approach
    By diegum in forum Architecture
    Replies: 9
    Last Post: May 10th, 2007, 04:09 PM
  2. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  3. Replies: 1
    Last Post: May 25th, 2005, 10:22 AM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •