2015-07-02

How do I use DataMapper Pattern? I can use it as a glorified Database Access Object, aka TableGateway (loading a single class from a single database table), or I can use it more to drive business concerns (i.e. load complex objects from many DB tables). Or mix both?

Example

Suppose that in my business application I have a Product and a Motor entities. Sometimes I need just one and sometimes just the other. But sometimes I need a structure where a motor belongs to a product. (Product owns the Motor), and I need to load both, and I can create and use a single function of my DataMapper to do that.

Business-Oriented Naming/Structure

TableGateway Naming/Structure

Question

My question deals with "What was/is the intent of use of DataMapper pattern?"

Is there intent to use as a business layer (namely load business-relevant objects with DataMapper functions creating complex business-relevant objects), or is it purely intended to do simple Create/Update/Delete/Insert functions and is to disconnect itself from creating business-relevant-objects, leaving that to some business functionality layer?

Show more