Class design

J

Jarmo

I need to design an Employee object that represents data stored in two
distinct databases (yes, it has to be in both). Each of the database
records has a common set of fields but also a few specific fields each. I
have one class (EmployeeC1) that represents an Employee record in database#1
and a distinct class (EmployeeC2) that represents an Employee record in
database#2. I've toyed with various class designs (including some using
interfaces) but have not come up with anything better than the following
basic definition:

class Employee {
private EmployeeC1 rec1;
private EmployeeC2 rec2;

public Employee() {
rec1 = new EmployeeC1();
rec2 = new EmployeeC2();
}

public Employee(int id) throws GetError {
rec1 = db1.get("id", id);
rec2 = db2.get("id", id);
}

public insert() throws InsertError {
db1.insert(rec1);
db2.insert(rec2);
}
}

Is there a more obvious, and better, design? Thanks.
 
C

Chris Smith

Jarmo said:
class Employee {
private EmployeeC1 rec1;
private EmployeeC2 rec2;

public Employee() {
rec1 = new EmployeeC1();
rec2 = new EmployeeC2();
}

public Employee(int id) throws GetError {
rec1 = db1.get("id", id);
rec2 = db2.get("id", id);
}

public insert() throws InsertError {
db1.insert(rec1);
db2.insert(rec2);
}
}

Is there a more obvious, and better, design? Thanks.

Depends. That's the simplest way. But do you need transactional
integrity across the databases? If so, then you're better off going for
an existing data-mapping package, because the problem gets very hard,
and very fast. If you aren't concerned with cross-database
transactional integrity, then yeah I'd go for the simple approach you
have.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
J

Jarmo

Chris Smith said:
Depends. That's the simplest way. But do you need transactional
integrity across the databases? If so, then you're better off going for
an existing data-mapping package, because the problem gets very hard,
and very fast. If you aren't concerned with cross-database
transactional integrity, then yeah I'd go for the simple approach you
have.

Thanks Chris.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top