I have been working on creating a database backed web application as an educational project, unfortunately I've hit a snag in the design. As background, I have a "Home" and a "Region" model (classes). I also have separate DAO classes to handle interaction with the database (HomeDAO and RegionDAO). As you can probably guess, homes are organized by regions (groups of homes belong to certain regions) and now I am trying to create a method that lists each home for a certain region, something like listHomesByRegion(). My issue is I'm not sure how to create this method or where it should go. Most of my DAO code has come from this site: http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html and below is a sample of what I was planning on using inside of the RegionDAO class:
Now in theory this works fine but my issue is this: the mapHome method from above already exists in the HomeDAO class but is marked private as it's designed to only be called by HomeDAO. For that reason, I can't just import HomeDAO into RegionDAO and use that method which means I have to re-create it in my RegionDAO class which leads to code duplication and two identical methods I have to maintain (not the best solution). So what is the best way to tackle this from a design perspective? I thought about moving the entire listHomesByRegion() method into the HomeDAO class but that doesn't seem like a very good solution either.