Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First I think the title of the question isn't very clear, second I'm not entirely sure I understand what is being asked... In my opinion both the title and the post really should be edited to clean it up a bit.</p> <p>The post seems to contain 5 questions (if I might paraphrase):</p> <ol> <li>How would one go about retrieving a dependent/parent object from an entity?</li> <li>Is <code>$person-&gt;getAddress()</code> a good way to retrieve the Address object for a person from the database?</li> <li>If this a good way to do it then what would the code look like?</li> <li>Is it okay to use the $domain object inside the getAddress method?</li> <li>Is it okay to keep relation information in the Person class?</li> </ol> <p>As far as answers go:</p> <ol> <li>In this case <code>$person-&gt;getAddress()</code> seems a good choice, you know, nice and descriptive. ;-)</li> <li>I don't see a problem: Person <strong>HAS A</strong> Address, to get that adress you ask the person object for is.</li> <li>The given code example seems to answer this, although it is a bit cluttered. I would've just made address a member object, but other than that it's mostly the same</li> <li>&amp; 5. I'd say are mostly a matter of taste, priority and design-dependency. There really isn't a clean cut answer to this. Also, are we arguing semantics here or a real life scenario?</li> </ol> <p>Some code to go along with answer Nr.3: (I couldn't get it to work properly within the list) </p> <pre><code>class Person { protected $_domain = null; // domain is assigned when instantiated protected $_address; // object public function getAddress() { if (!isset($this-&gt;_address) ) { $this-&gt;_address = $this-&gt;_domain-&gt;getAddressForPerson($this); // assuming $this contains some sort of ID } return $this-&gt;_address; } } </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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