[TYPO3-mvc] Cloning properties in setter and getter methods of models (blog example)

Thomas "Thasmo" Deinhamer thasmo at gmail.com
Sat Feb 12 01:26:42 CET 2011


Franz Koch wrote:
> Now do we really want just clones all over the place? Using clones
> everywhere would also make chained calles pretty ineffective.

Okay, well then - you got me confused. :>

As a general rule I'd say then, that the default
is to pass the original objects in general and only
in certain cases cloning should be used.

But then there's still one problem I don't like:
If a special case arises, where a cloned object
is returned by the getter, someone maybe expects
to get the original object as this may be the default.

And let's assume a clone is returned because the EXT
author wants the developer to use a specific setter
method of the model, because there's some magic in
the setter, which would modify stuff etc.

So, the only 'clean' solution to this (= consistent
API [no cloning], but still the magic modifications
on new properties) would be to have a method called
something like persistObject() or similar, which
would be called before the object gets persisted,
so the magic could happen there, without the need
to return any cloned objects and without the need
to put custom code in the setters.

Hopefully that was understandable.

oO

What's your opinion on that?

Thanks,
Thomas


More information about the TYPO3-project-typo3v4mvc mailing list