Anemic Domain Model, Business Logic and DataMapper (PHP)
Posted
by
sunwukung
on Programmers
See other posts from Programmers
or by sunwukung
Published on 2011-03-09T17:19:06Z
Indexed on
2011/03/10
0:18 UTC
Read the original article
Hit count: 249
I've implemented a rudimentary ORM layer based on DataMapper (I don't want to use a full blown ORM like Propel/Doctrine - for anything beyond simple fetch/save ops I prefer to access the data directly layer using a SQL abstraction layer).
Following the DataMapper pattern, I've endeavoured to keep all persistence operations in the Mapper - including the location of related entities.
My Entities have access to their Mapper, although I try not to call Mapper logic from the Entity interface (although this would be simple enough). The result is:
// get a mapper and produce an entity
$ProductMapper = $di->get('product_mapper');
$Product = $ProductMapper->find('[email protected]','email');
//.. mutaute some values.. save
$ProductMapper->save($Product)
// uses __get to trigger relation acquisition
$Manufacturer = $Product->manufacturer;
I've read some articles regarding the concept of an Anemic Domain model, i.e. a Model that does not contain any "business logic". When demonstrating the sort of business logic ideally suited to a Domain Model, however, acquiring related data items is a common example.
Therefore I wanted to ask this question: Is persistence logic appropriate in Domain Model objects?
© Programmers or respective owner