Objects by Design Forums Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home  
Objects by Design Forums : Powered by vBulletin version 2.3.5 Objects by Design Forums > Main Forums > Object-Oriented Design and Patterns > What is the best DAO approach?
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
unmeshjoshi
Junior Member

Registered: Aug 2005
Location:
Posts: 1

What is the best DAO approach?

Hi,

I have a question regarding use of Domain Model pattern. In our project we are creating customer profiles. We have modeled profile like this

class Profile {
Name name;
List<Address> addressList;
List <Phone> phoneList;
....
}

We have CRUD operations for Profile, Addresses, and Phones.
For crud operations, we have DAO facade like this

class ProfileDao {
void insertProfile(Profile profile);
void Profile getProfile(String profileId);
void addAddress(String profileId, Address a);
void addPhone(String profileId, Phone p);
void updateAddress(String addressId, Address a);
void updatePhone(String phoneId, Phone p);
void deleteAddress(String addressId);
void deletePhone(String phoneId);
..........

}


Client for this code will be like this.

class ProfileClient {
void testAddAddress() {
Address address = new Address("112 Fifth Street", "NJ", "US", "08857");

String profileId = getProfileIdentifier();

getProfileDao().update(profileId, address);

}
}

Instead of using Facade like this, I thought we could use it like following.

1. Clients will do all CRUD operations on Profile object itself.
2. All the classes will have isUpdated, isNew and isDeleted flag.
3. Dao will have just one update(Profile p) method.
4. Dao will check for updates and make queries accordingly

Dao will now become like this.

class ProfileDao {
void insertProfile(Profile profile);
void Profile getProfile(String profileId);
void update(Profile p);
}

Client for this code will be like this.

class ProfileClient {

void testAddAddress() {
Address address = new Address("112 Fifth Street", "NJ", "US", "08857");
Profile p = getProfile();
p.addAddress(address);

getProfileDao().update(profile);

}
}

This second approach looks cleaner, but the concern raised by my team mates is that every time I need to add, update, delete a single address, I need to load whole profile object in memory. This looks more like a "stateful" implementation as opposed to "stateless" implementation of Dao Facade. If Profile object is a huge one, then it can be a overkill to load the whole object just to add/change one address. But I certainly dont like the facade implementation. It does not allow me to do inserts/updates/deletes in batch. I have to do operations one at a time. Secondly any object level validations or business rules (Like Profile should have only one delivery address) are harder to implement in facade approach. What is your opinion on this? Is this a standard Domain Model vs Transaction Script issue?

I tried these solutions with TDD, the second I found more testable. What do you think?


Thanks,
Unmesh

Report this post to a moderator | IP: Logged

Old Post 08-21-2005 03:10 AM
unmeshjoshi is offline Click Here to See the Profile for unmeshjoshi Click here to Send unmeshjoshi a Private Message Find more posts by unmeshjoshi Add unmeshjoshi to your buddy list Edit/Delete Message Reply w/Quote
vsatija
Junior Member

Registered: Oct 2005
Location:
Posts: 7

Hi,

Both the design classes that you are using are more or less fine. Since any code using the class ProfileDao will be considered as a client of ProfileDao class. So my suggestion would be to have both types of interfaces i.e.

void addAddress(String profileId, Address a);
void update(Profile& p);

With this approach we can have advantages of both types of interface. When you have to update more than one attribute of the profile class then probably you can use the update interface.

I hope you like my suggestion.

Regards,
Vipin Satija

Report this post to a moderator | IP: Logged

Old Post 12-21-2005 05:17 AM
vsatija is offline Click Here to See the Profile for vsatija Click here to Send vsatija a Private Message Find more posts by vsatija Add vsatija to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 11:40 PM. Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 

< Contact Us - Objects by Design >

Powered by: vBulletin Version 2.3.5
Copyright ©2000 - 2018, Jelsoft Enterprises Limited.
Copyright 1999-2005, Objects by Design, Inc.