Note that there are some explanatory texts on larger screens.

plurals
  1. PO1:n relation in OOP regarding to deserialisation
    primarykey
    data
    text
    <p>I've modeled two classes like this:</p> <pre><code>ClassA -- n:1 --&gt; ClassB </code></pre> <p>ClassB knows nothing about ClassA (unidirectional relation). Now I'm currently writing a file loader for ClassA that <em>uses</em> (and does <em>not own</em>) a ClassB object.</p> <p>Code-wise ClassA holds a pointer to ClassB, and that is where my problem arises: The loader is responsible for loading ClassA only and doesn't have access to the container that contains all the ClassB objects, so it's not possible to establish the relation.</p> <p>A solution would be to insert a string member to ClassA that contains the id of the ClassB object, so the relation can be established later. The question is, however, if there are any other approaches that solve this problem. I don't need the id after loading anymore, therefore I'd like to leave it out.</p> <p><strong>Example of a ClassA file that shall be loaded:</strong></p> <pre><code>Id: "some-id" # Irrelevant for this example. ;-) ClassB: "some-classb-id" </code></pre> <p>ClassA holds <strong>one</strong> pointer to a ClassB object. The loader now deserialises ClassA and does <strong>not</strong> load any ClassB objects, instead only a relation is about to be established to an already <strong>existing</strong> ClassB object. The reason for this is that ClassB objects are pre-loaded and ClassA objects can be added during runtime.</p> <p>The ClassB pointer in ClassA <em>may be NULL</em>, that's completely okay (it's an optional relation).</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