[TYPO3-mvc] questions: @lazy, @inject, @api, constructors

Jochen Rau jochen.rau at typoplanet.de
Fri Jan 15 13:49:01 CET 2010


Hi,

(slowly catching up with all the topics since Julia was born on Jan, 10th.)

On 15.01.10 11:47, Martin Kutschker wrote:
> Franz Koch schrieb:
>> Hi,
>>
>>>> 4. Is there a guideline/good practice rule which defines which fields of
>>>> a class should be initialized in its constructor?
>>> - definitely all ObjectStorages (Tx_Extbase_Persistence_ObjectStorage)
>>
>> I wonder why I have to define all ObjectStorages in the constructor when
>> the constructor is never called from inside extbase. Non automatically
>> persisted/injected objects get built calling the constructor. I noticed
>> this when I actually defined a ObjectStorage in the constructor and
>> tried to used it in a getter/setter method.
>
> If I understand correctly a reconstitution from DB will (read: "should") create the ObjectStorages
> automatically.

It does. The DataMapper "reads" the property definition and instanciates 
the ObjectStorage on the fly. If you don't initialize the ObjectStorage 
on build-time it could be confusing that this new object has NULL asl 
property value while the reconstituted object has an (empty) 
ObjectStorage as value.

It's good practice IMO to initialize all properties before the are used 
the first time.

Regards
Jochen


More information about the TYPO3-project-typo3v4mvc mailing list