(on Thursday, 11 June 2009, 07:28 AM +0100):
> 2009/6/10 Fábio Locatelli <flocatelli@gmail.com>:
> > I am new on this list. I am enjoying it so far.
> >
> > I was passing by the official Zend Quick start to see whats new and I liked
> > the idea of Data Mapper introduced by Ralph Schindler. Ralph made a good
> > job introducing this pattern for new users. I confess I was expecting
> > ZF would implement this.
Just for the record... I was the one who rewrote the quick start to add
the Data Mapper during this iteration -- though I had Ralph review it
before we posted it. It's an idea the two of us have discussed to some
length in the past.
> > I found another good article at google,
> > http://blog.tekerson.com/2008/12/17/data-mapper-pattern-in-php and
> > http://akrabat.com/2008/12/13/on-models-in-a-zend-framework-application/
> >
> > I thought data mapper very interesting I intend to include it at our next
> > projects.
> >
> > Anyway! Does someone have implement data mapper as a abstract or generic
> > class and wants to share?
>
> A data mapper is actually quite complex to implement properly,
> generally it is used along side the Domain Model pattern, which again
> is very hard to implement correctly, you may want to look at the data
> mapper proposal on the wiki
>
> http://framework.zend.com/wiki/display/ZFPROP/Zend_Db_Mapper+-+Benjamin+Eberlei
>
> As you can see when creating/using a data mapper there are many issues
> that need to be dealt with such as the object life cycle etc.
Actually, data mappers and domain models can be trivially simple or
tremendously complex -- the difficulty will depend on the complexity of
your models and/or persistence layer.
Domain models are simply classes -- you are defining metadata and/or
behavior. Data mappers are used to map the model to a stateful layer
(since PHP is stateless, this layer is necessary if you wish to persist
the data for later retrieval). If you have a single model hitting a
single table, it can be incredibly simple. However, when you start
looking at 1:N and N:N relationships, they can become much more complex.
They are not impossible for the average developer to create -- but
they're not exactly trivial, either. Generic implementations are
incredibly hard to get right, however, and many would argue that generic
implementations become too cumbersome to be worth while.
> If you are really interested in this subject I suggest reading martin
> fowlers patterns of enterprise architecture book and domain driven
> design by eric evans...
I'll second those recommendations.
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论