This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes OOP question (where does this method go?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OOP question (where does this method go?)" Watch "OOP question (where does this method go?)" New topic

OOP question (where does this method go?)

J Sellers

Joined: Mar 06, 2009
Posts: 10
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: 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.
David Newton

Joined: Sep 29, 2008
Posts: 12617

Personally, I tend to create services that access DAO methods.
I agree. Here's the link:
subject: OOP question (where does this method go?)
It's not a secret anymore!