1

I have a class User which has the property address which is an instance of Address. I am using the Table Data Gateway pattern to manage the persistence of the User object.

Assuming the Address class has its own Table Gateway, who should be responsible for setting the User's address property?

As an example of what I am asking in PHP:

<?php
$user = $userTableGateway->getUserWithId(5); // \My\Classes\User
$address = $user->address; // \My\Classes\Address  <-- Who makes sure this exists?
?>
nathanjosiah
  • 4,441
  • 4
  • 35
  • 47
  • What do you mean "who?" If I understand that pattern correctly, it's basically a CRUD object. The object itself is responsible for setting values. – Robert Harvey Feb 12 '14 at 00:05
  • The object itself is responsible for restoring the state of other objects? That would violate the domain model pattern and the law of demeter. When I say who I mean where in the structure would be responsible for restoring the state of the associated object. – nathanjosiah Feb 12 '14 at 00:06
  • The Table Data Gateway maintains a *database table.* The database table is what holds the state. Are you sure you understand the pattern? What does LOD have to do with anything? Stop using buzzwords until you understand what they mean. – Robert Harvey Feb 12 '14 at 00:07
  • That's part of my question though, I understand the purpose of the table gateway but where in the code should be responsible for restoring the associated objects using the associated objects table gateway? Using a table gateway from within another table gateway doesn't seem right. – nathanjosiah Feb 12 '14 at 00:08
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47275/discussion-between-robert-harvey-and-nathanjosiah) – Robert Harvey Feb 12 '14 at 00:10

0 Answers0