[TYPO3-mvc] Cloning properties in setter and getter methods of models (blog example)
Franz Koch
typo3.RemoveForMessage at elements-net.de
Fri Feb 11 16:11:57 CET 2011
Hey,
> Some time ago (maybe still present), in the blog example,
> properties in setter and getter methods were cloned like this:
>
> public function setStocks(Tx_Extbase_Persistence_ObjectStorage $stocks) {
> $this->stocks = clone $stocks;
> }
>
> public function getStocks() {
> return clone $this->stocks;
> }
>
> What's the reason for this and is it better
> to use it also in own extensions?
in general you use clones for cases where you don't want that any change
to this object should get persisted. The reason why it's used in the
blogExample might be that by doing this you force anyone working with
the object to use the according methods from the model to alter the
objectStorages (which might not be the worst reason to have). So one
can't simply fetch all Tags and add a new one to this objectStorage
which would be out of the scope of the domain models responsibility
(because maybe the setter from the domain model is triggering some
additional methods that depend on the setter etc).
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list