aspose file tools*
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 Spring in Action this week in the Spring 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
Author

OOP question (where does this method go?)

J Sellers
Greenhorn

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: 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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Personally, I tend to create services that access DAO methods.
 
Don't get me started about those stupid light bulbs.
 
subject: OOP question (where does this method go?)