• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

OOP question (where does this method go?)

Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I tend to create services that access DAO methods.
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic