• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

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

 
Ranch Hand
Posts: 58
2
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic