2009年9月1日星期二

[fw-mvc] Understanding 'Service Layer' and 'Domain Model'

Wondered if anyone might be able to help.

I have been reading Matthew Weier O'Phinney's Zend Framework slides from the 2009 Dutch PHP Conference (thank you Matthew for making the slides available, they have been extremely useful).

One aspect I am trying to understand is determining what to put in the service layer and what to put in the domain model. I don't fully understand the difference. I just wondered whether anyone may be able to give a small example/explanation.

An example of my confusion is as follows. If I have a controller which requests a list of users from the service layer. Sometimes I want all users, and sometimes current users (status of 1), would I have 2 methods each (e.g. fetchUsers, fetchCurrentUsers) in the service layer, the domain model AND the data mapper code?

Or would I have a fetchAll method in the Data Mapper and call from the domain model:
 function fetchUsers() {     $dataMapper->fetchAll(array()); }  function fetchCurrentUsers() {     $dataMapper->fetchAll(array('status' => 1)); } 
or have a fetchAll in the domain Model and call from the service layer:
 function fetchUsers() {     $domainModel->fetchAll(array()); }  function fetchCurrentUsers() {     $domainModel->fetchAll(array('status' => 1)); } 
My problem actually stemmed from having a query which joined 2 tables containing a 'status' column which meant I needed to specify somewhere that my status was for the user table. So, I would need:
 function fetchBannedUsers() {     $domainModel->fetchAll(array('u.status' => 1)); } 
But should the service layer 'know' about the database structure?

Colin

View this message in context: Understanding 'Service Layer' and 'Domain Model'
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: