all groups > visual studio .net general > february 2005 >
You're in the

visual studio .net general

group:

CodeModel


CodeModel r.bouchut NO[at]SPAM algorys.com
2/24/2005 5:08:03 AM
visual studio .net general:
Hi,

I have an object A that contain B. When I create B I want to add a
property (parent) that point to the instance of A (if the instance of
B is contained in A).
If B is instanciated alone (not in A), is parent will be set to
nothing.
I add a parameter in the constructor to add the parent but I want it
to be transparent for the developper. When B is created, "he knows"
his parent is A.

Re: CodeModel Carlos J. Quintero [.NET MVP]
2/25/2005 10:02:45 AM
This group is for Visual Studio .NET (the tool) questions, not for .NET
language questions. Microsoft.public.dotnet.languages.* groups are more
helpful for those questions. Said that, if you code:

b = New B()

there is no way for B to know who is its parent if you don´t pass it as
parameter (or setting a property after creation):

b = New B(a)

or

b = New B()
b.Parent = a;

So, to make it transparent for the programmer, you need to create B from a
method of A:

b = a.CreateB()

and internally in the CreateB function you do:

b = New B(Me)
Return b

and to avoid creation of B without calling that factory method, you do:

Private Sub New() ' Private scope prevents calls to this constructor
End Sub

and

Friend Sub New(ByVal a As A) ' Friend scope prevents calls to this
constructor outside the class library (forcing to use the factory method)
End Sub

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com


"bulfrog" <r.bouchut@algorys.com> escribió en el mensaje
news:953a7fbc.0502240508.480009ff@posting.google.com...
[quoted text, click to view]

AddThis Social Bookmark Button