0

It has become common to treat models in ZF as pure data objects, i.e. a class instance with a bunch of attributes and getters/setters.

class Model_User {
  public $id;
  public $name;
  ...
}

What I'm wondering is whether or not it makes sense to, for example, instantiate such an object in a controller and pass it to a service layer, or whether or not the service layer should itself be responsible for instantiating these objects... You would not instantiate a Zend_DbTable class directly in the controller, so does it make much sense to instantiate a Model_User in a controller to pass it to a service?

dianovich
  • 2,288
  • 21
  • 34
  • My reason for asking this is that I often find myself passing arrays from a controller to a service layer only to then pass them straight to a model... – dianovich Jan 31 '12 at 16:29

1 Answers1

0

I don't see a problem with doing it this way. Data Transport Objects (DTO) are meant to pass information between layers and/or modules. In my opinion this is no different that using arrays and it certainly is easier than using arrays.

Here is another discussion over DTOs - What is Data Transfer Object?

And Martin's definition on DTOs - http://martinfowler.com/eaaCatalog/dataTransferObject.html

Community
  • 1
  • 1
Jeremiah
  • 751
  • 9
  • 21