Win a copy of Head First Android this week in the Android forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Controller-Service-Repository: Should Repositories depend on other Repositories?

Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's say we have a couple of classes; Brand and Supplier, where Supplier is a property of Brand.

We have the following interfaces à la the Controller-Service-Repository pattern: BrandService, BrandRepository, SupplierService, SupplierRepository.

Within an a JDBC implementation of BrandRepository, we implement this method: public Brand find(int brandId). Within this method we retrieve brand.supplier_id within the SQL query, and we wish- somehow- to use it to set the Supplier property on the Brand object. The most obvious way to do this is to inject a SupplierRepository into the BrandRepository implementation, and just call public Supplier find(int supplierId) on that.

Do you have strong objections to this? If so, could you outline a preferable alternative?

I'm less interested in the specifics of this example than I am the general principle of whether it's ever okay for a Repository to depend on another.

Many thanks.
    Bookmark Topic Watch Topic
  • New Topic