mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-11 01:14:01 +02:00
Change index.rst to README.rst
remove all pattern's README.md
This commit is contained in:
60
Structural/DataMapper/README.rst
Normal file
60
Structural/DataMapper/README.rst
Normal file
@@ -0,0 +1,60 @@
|
||||
`Data Mapper`_
|
||||
==============
|
||||
|
||||
Purpose
|
||||
-------
|
||||
|
||||
A Data Mapper, is a Data Access Layer that performs bidirectional
|
||||
transfer of data between a persistent data store (often a relational
|
||||
database) and an in memory data representation (the domain layer). The
|
||||
goal of the pattern is to keep the in memory representation and the
|
||||
persistent data store independent of each other and the data mapper
|
||||
itself. The layer is composed of one or more mappers (or Data Access
|
||||
Objects), performing the data transfer. Mapper implementations vary in
|
||||
scope. Generic mappers will handle many different domain entity types,
|
||||
dedicated mappers will handle one or a few.
|
||||
|
||||
The key point of this pattern is, unlike Active Record pattern, the data
|
||||
model follows Single Responsibility Principle.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
- DB Object Relational Mapper (ORM) : Doctrine2 uses DAO named as
|
||||
"EntityRepository"
|
||||
|
||||
UML Diagram
|
||||
-----------
|
||||
|
||||
.. image:: uml/uml.png
|
||||
:alt: Alt DataMapper UML Diagram
|
||||
:align: center
|
||||
|
||||
Code
|
||||
----
|
||||
|
||||
You can also find these code on `GitHub`_
|
||||
|
||||
UserMapper.php
|
||||
|
||||
.. literalinclude:: UserMapper.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
User.php
|
||||
|
||||
.. literalinclude:: User.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
Test
|
||||
----
|
||||
|
||||
Tests/DataMapperTest.php
|
||||
|
||||
.. literalinclude:: Tests/DataMapperTest.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/DataMapper
|
||||
.. _`Data Mapper`: http://en.wikipedia.org/wiki/Data_mapper_pattern
|
Reference in New Issue
Block a user