Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Catégorie:
Programmation Orientée Object
Versions des environnements
>I was passing in an object, oHandler, to another object, oxServer, but decided I want to create oHandler inside oxServer instead, to keep everything encapsulated so references are easier to make. What decides when to use NewObject, CreateObject or AddObject? I was using CreateObject for oHandler, then passing it in, but what's the correct way to do it inside oxServer? Why?
>
>As a generally rule, I use Composition ( AddObject ) rather than Aggregation ( NewObject or CreateObject ) whenever possible because the container object "owns" all of the contained items. When the container is destroyed, all of its contained objects are destroyed too. So the chances of a dangling reference are greatly reduced.
Good information, thanks! I still can't understand why, when I create an object while in another object, the child does not have a parent. That goes against logic to me, but not knowing the rules, maybe it doesn't.
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement