Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Parent Child Relationships
Message
De
15/12/2009 14:32:08
 
 
À
15/12/2009 13:45:06
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01438981
Message ID:
01439226
Vues:
27
>>>>Sometimes when creating a parent child relationship the child may need to know who it's parent is.
>>>>
>>>>I can do that easy enough by passing the parent reference in the constructor for the child.
>>>>
>>>>In C# do I need to worry about the circular reference I've just created?
>>>
>>>Not 100% sure of your context. Bonnie mentioned the problem with assemblies but I think you're asking about simple objects like:
public class ClassA
>>>    {
>>>        ClassB B;
>>>        public ClassA(ClassB b)
>>>        { B = b; }
>>>    }
>>>
>>>    public class ClassB
>>>    {
>>>        ClassA A;
>>>        public ClassB()
>>>        {A = new ClassA(this);}
>>>    }
If so then there's not a problem. See:http://msdn.microsoft.com/en-us/library/0t81zye4(VS.71).aspx
>>>
>>>Best,
>>>Viv
>>
>>Yep simple objects, all within the same assembly. Parent has a lot of properties/resources that it's children need to be able to work with. Parent won't change once created so no need for events.
>>
>>Somewhere early on I got the idea this was not a desirable pattern and the circular reference between assemblies answers were plugging up my google results. It looked like I was OK, but I wanted to be sure. These are rather major classes.
>>
>>Thanks for the answers everyone.
>
>Whilst the 'circular reference' is not able to cause a real problem it might be worth implementing IDisposable on those classes ?

I was curious about that. Not sure if it would speed up the GC up a bunch or not. The classes I'm doing this on won't change that frequently so I'm not sure it's needed even if it would.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform