Exforsys

Online Training

Objects and Data Access Patterns Question

This is a discussion on Objects and Data Access Patterns Question within the Software Patterns forums, part of the Testing category; I know very little about the different patterns, but have a question whether particular patterns exist for two issues I ...


Go Back   Exforsys > Testing > Software Patterns

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-23-2004, 02:29 PM
nick
Guest
 
Posts: n/a
Objects and Data Access Patterns Question

I know very little about the different patterns, but have a question
whether particular patterns exist for two issues I have. I assume they
do since my problem I would expect are quite common. Problem 1 is
this:

Say I have a user class (User) and subscription class (Subscription).
The data for both the User and Subscription classes is kept in a
database in two tables, Users and Subscriptions. Users are identified
by ID (both a property of the Object and a field in the DB).
Subscriptions are identified by ID (both a property of the Object and
a field in the DB). A user can have many subscriptions, so the User
class has a property called Subscriptions which is an array.

The first question is regarding whether when I instantiate a User
based on ID I should also populate the User.Subscriptions array. On
the one hand, it is part of the definition of User. One the other
hand, it requires another call to the DB to get all the subscriptions
based on User.ID. Would it be better to add a GetSubscriptions method
to populate the array on demand. This also has implications when
calling a User.Update method, for example. In the Update method do I
update the data in the Users table and also the Subscriptions? Or
should I have a seperate method UpdateSubscriptions to update the
Subscriptions table. I know it's not very complicated and possibly a
matter of taste, but are there patters which answer these questions?

The second question is regarding whether to store Subscription.IDs in
the User.Subscriptions array or actual Subscription objects. If I
store ID's I only have to go to the DB once when I get the
subscriptions for the User. If I store Subscription objects themselves
in User.Subscriptions, then when I get the subscriptions for the User,
I also have to go to the DB for each and every Subscription object
being instantiated. This seems like a lot of work when often I'll only
need the IDs. On the other hand it seems much cleaner and OO like to
store actual Subscription Objects.

Thanks for any help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:21 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.