class design vs. db design

J

John_Woo

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?
 
O

Oliver Wong

John_Woo said:
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
 
J

John_Woo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top