[TYPO3-mvc] Mapping various Objects to a Domain Model

Thomas "Thasmo" Deinhamer thasmo at gmail.com
Tue Jun 12 20:49:00 CEST 2012


Hello folks,

I have a similar domain object tree,
with single table inheritance:

Server
   ServerA
   ServerB
   ServerC

Now I have some simple objects, which
hold some kind of "raw" data, which should
be mapped to those domain objects.

The simple object's structure is quite similar:

Object
   ObjectA
   ObjectB
   ObjectC

Both, the domain objects and the simple objects
have a certain amount of same named properties,
but the properties of the simple objects must
be mapped/converted to fit the property validation
of the domain objects.

Imagine "ObjectA" has a property "status" which's
value can be "(string)ON" and "(string)OFF".

The property "status" of the domain model "ServerA"
has an equivalent property valued "(boolean)TRUE" or
"(boolean)FALSE" which should be mapped from the
property of "ObjectA".

How would I do this in a nice and extendable way?

I thought of adding a method "addObject(ObjectA $object)
to each "Server" domain model, but this feels odd to me.

Another way probably would be to create a "mapper"
for each "Server:Object" pair which deals with it.

Mapper
   MapperA
   MapperB
   MapperC

But this means a lot of classes to deal with,
although it should be cleaner than a model method.

Is there a preferred solution for this type of process?
Is there any known design pattern which can solve this?

Thanks a lot for your feedback!

Thomas


More information about the TYPO3-project-typo3v4mvc mailing list