I am writing a Java program using the MVC design pattern.

I have classes Item and Supplier. In the database they are connected through a item_supplier table.

I'm writing a method which will give me all suppliers for a specific item (using itemID):

public ArrayList<Supplier> getItemSuppliers(int itemID)

I have a DB layer as well and I have DBItem and DBSupplier. Where should this method go? I will use it only (mostly) on my ItemUI so I am thinking of DBItem as the correct place.


Usually when we have the SalesLineItem pattern (Sales * - 1 SalesLineItem 1 - * Item) we have a separate class, but in that case, do I need such as my only interaction with that table (item_supplier) will be with this printing (and one updating) method?

Basically, do I need to do a ItemSupplier model layer class and respectively DBItemSupplier or can I just have those two methods getItemSuppliers and updateItemSuppliers on either DBItem or DBSupplier (and if the latter, where?)

  • 1
    Why not have an ItemService Class? – Amy Blankenship May 26 '13 at 22:56
  • DBItem and BDSupplier are bad names because they lie. Do DBSuppliers supply databases ? If they don't then the name lies. – Tulains Córdova May 27 '13 at 19:57
  • DBItem and DBSupplier are my classes for respectively Item and Supplier in the DB Layer. I also have IFItem and IFSupplier which are the interfaces. – Nikola May 27 '13 at 20:08

Putting that method on your DBItem class is probably the right thing to do. I assume that the DBItem class encapsulates all the queries necessary to receive the data associated with an item, in which case this is the correct thing to do.

As for whether you need the joining table in your Many-to-Many relationship, probably not. You usually do not need to represent this joining table in your model layer, it is enough to have Item.Suppliers and Supplier.Items collections on your model classes.


I should point out, that there is a fairly simple question to ask, in order to decide whether to include the joining table at your model layer: "is this table a weak entity, or a strong entity?". If it is a weak entity then you don't have to include. Now, what is a weak entity? A weak entity is one that would not exist on its own, ie it simply joins to other entities together. In fact, even if it had other properties of the relationship between those two other entities, if it wouldn't make sense to have one or other end of the relationship missing (or both missing even), then it is a weak entity. Of course if your weak entity had properties that you wanted to surface through your model, you might decide to include it anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.