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.
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.