Class design

Discussion in 'Java' started by Jarmo, Dec 16, 2003.

  1. Jarmo

    Jarmo Guest

    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.
     
    Jarmo, Dec 16, 2003
    #1
    1. Advertising

  2. Jarmo

    Chris Smith Guest

    Jarmo wrote:
    > 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
     
    Chris Smith, Dec 16, 2003
    #2
    1. Advertising

  3. Jarmo

    Jarmo Guest

    "Chris Smith" <> wrote in message
    news:4.net...
    >
    > 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.
     
    Jarmo, Dec 16, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,944
    Thomas Weidenfeller
    Oct 12, 2005
  2. christopher diggins
    Replies:
    16
    Views:
    786
    Pete Becker
    May 4, 2005
  3. John_Woo

    class design vs. db design

    John_Woo, Dec 19, 2006, in forum: Java
    Replies:
    2
    Views:
    355
    John_Woo
    Dec 19, 2006
  4. Joseph Turian
    Replies:
    5
    Views:
    628
  5. Bartholomew Simpson

    class design/ design pattern question

    Bartholomew Simpson, Jun 12, 2007, in forum: C++
    Replies:
    2
    Views:
    462
    Daniel T.
    Jun 12, 2007
Loading...

Share This Page