Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > class design vs. db design

Reply
Thread Tools

class design vs. db design

 
 
John_Woo
Guest
Posts: n/a
 
      12-19-2006
Hi,

if I want to reflect a 1:1 relationship for user:account, the design
model may be:

for class:
A. User
-------------
int user_id;
int account_id;

B. User
------------
int user_id;
Account account;

for db:
C. User (user_id int); Account(account_id int, user_id int)

D. User (user_id int, account_id int); Account (account_id int)

Questions:
1. How to compare A vs. B in terms of OO design, JDO (java data object)

2. How to compare A vs. B in terms of db schema (with foreign key
constraint)

3. C vs. D, which is better? should create user first or account first?

---
Thanks
John
Toronto

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      12-19-2006
"John_Woo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hi,
>
> if I want to reflect a 1:1 relationship for user:account, the design
> model may be:
>
> for class:
> A. User
> -------------
> int user_id;
> int account_id;
>
> B. User
> ------------
> int user_id;
> Account account;
>
> for db:
> C. User (user_id int); Account(account_id int, user_id int)
>
> D. User (user_id int, account_id int); Account (account_id int)
>
> Questions:
> 1. How to compare A vs. B in terms of OO design, JDO (java data object)


I like B better. It looks like less work to get the account from the
user.

>
> 2. How to compare A vs. B in terms of db schema (with foreign key
> constraint)


I suppose A would be slightly less work to implement a ORM for, but you
could just download an ORM like Hibernate to do the work for you, so I'd
still stick with B.

>
> 3. C vs. D, which is better? should create user first or account first?


If the relation is 1:1, why not stick it all in one big table?

- Oliver


 
Reply With Quote
 
 
 
 
John_Woo
Guest
Posts: n/a
 
      12-19-2006

> > for db:
> > C. User (user_id int); Account(account_id int, user_id int)
> >
> > D. User (user_id int, account_id int); Account (account_id int)
> >
> > 3. C vs. D, which is better? should create user first or account first?

>
> If the relation is 1:1, why not stick it all in one big table?
>

Good point, thanks, Oliver.

but both these two tables may extend, like USER may have 10+ fields,
same as Account table.
if they have to be separated, I'm still looking for tips on selection
of model C, D

John

 
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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class design/ design pattern question Bartholomew Simpson C++ 2 06-12-2007 08:51 PM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Class design/design pattern resources TomTom MCSD 2 10-09-2004 07:38 AM



Advertisments