Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
NewObject or CreateObject or AddObject
Message
De
28/08/2007 09:28:57
 
 
À
27/08/2007 16:16:40
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01250745
Message ID:
01250893
Vues:
18
This message has been marked as a message which has helped to the initial question of the thread.
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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform