Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3680660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:36:09+00:00 2026-05-19T03:36:09+00:00

I have two data access objects that are reverse generated and jar’ed up for

  • 0

I have two data access objects that are reverse generated and jar’ed up for use by my application. They represent tables that are very similar. One table has a few additional columns than the other. This is out of my control due to business oriented database ownership concerns.

The application currently has two implementations of a repository that operates on these DAOs. The implementations are very similar. One has a few extra operations that correspond to the extra columns on the second DAO. However with only a few exceptions, one implementation is a copy and paste of the other. The implementations are hundreds of lines long.

So I wanted to remove the copy/paste job. Ideally I could just stick an interface in front of the DAOs, and then maybe use an abstract class to hold the shared code (nearly all of it). However, I cannot put an interface in front of the DAOs. Remember they are reverse generated, and without upgrading our ORM software I don’t think this is a reasonable choice (Kodo 3.x I believe, changing this is not in scope).

The only thing I can think of that would even work is some nastiness with reflection but that results in something much worse than I have now.

Any clever solutions?

edit: Here is very watered down code example

package one.dao
//reverse generated
class UserDao {
    getFirstName(..);
    setFirstName(..);
    getLastName(..);
    .... 50 more just like this
}

package two.dao
//reverse generated
class UserDao {
    getFirstName(..);
    setFirstName(..);
    getLastName(..);
    .... the same 50 more as above

    getSomethingElse(..); //doesn't exist in one.dao.UserDao
    setSomethingElse(..); //doesn't exist in one.dao.UserDao
}

class RepositoryOne(one.dao.UserDao userDao) {
    //insert code here. perform operations on nearly all methods, lots of code
}

class RepositoryTwo(two.dao.UserDao userDao) {  
    //insert code here. same as Repository one

    //some extra code that isn't above, maybe 10 lines
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:36:09+00:00Added an answer on May 19, 2026 at 3:36 am

    I am assuming you have some control over the duplicated code. If your code generator is producing all of it, you’ll need to search for solutions within its API & configuration, I suspect.

    When Inheritance doesn’t work, try Composition. Make a third class to hold the shared code (SharedCode). Give each of the two existing classes a private member instance of the SharedCode class and make all routines implemented in SharedCode pass through methods to the member instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have a two dimensional array that I need to load data into. I
I have two processes one will query other for data.There will be huge amount
I have two files (f1 and f2) containing some text (or binary data). How
I have two projects, the DLL project which has all my logic and data
I have a two-dimensional array (of Strings) which make up my data table (of
I have two applications written in Java that communicate with each other using XML
I have two identical tables and need to copy rows from table to another.
I have conversion tables I need to contain in memory for fast access. Until
I am trying to test a class that manages data access in the database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.