Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramming a one-to-many relationship
    primarykey
    data
    text
    <p>So I am surprised that doing a search on google and stackoverflow doesn't return more results.</p> <p>In OO programming (I'm using java), how do you correctly implement a one-to-many relationship?</p> <p>I have a class <code>Customer</code> and class <code>Job</code>. My application is for a fictious company that completes jobs for customers. My current implementation is so that the <code>Job</code> class doesn't have anything to do with the <code>Customer</code> class, there is no reference to it at all. The <code>Customer</code> class uses a collection and methods to hold, retrieve and modify information about the Jobs that have been assigned by and/or completed for a customer.</p> <p>The question is, what if I'd want to find out for which customer a particular <code>Job</code> has been done? I've only found this article that's relevant: <a href="http://www.ibm.com/developerworks/webservices/library/ws-tip-objrel3/index.html" rel="noreferrer">http://www.ibm.com/developerworks/webservices/library/ws-tip-objrel3/index.html</a>.</p> <p>According to the implementation of the author, I would let the <code>Job</code> constructor take a <code>Customer</code> parameter, and store it so I can retrieve it. However, I see no guarantee at all that this model can be <strong>consistent</strong>. There are no restirctions to set the related customer for a job as a customer that the job was not for, and add jobs to customers that were done for someone else. Any help on this would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload