Child classes calling one anothers methods

  • Thread starter Thread starter Horace
  • Start date Start date
H

Horace

Hello

I have a class Parent1 that instantiates Child1 and Child2. But Child1
calls methods in Child2 like so :-

========================================
Imports Tiger_Devl.Includes.Child1
Imports Tiger_Devl.Includes.Child2

Namespace Includes
Public Class Parent1

Public This_Child1 As Includes.Child1
Public This_Child2 As Includes.Child2

Public Sub New()
This_Child1 = New Child1()
This_Child2 = New Child2()
End Sub
End Class
End Namespace
========================================
Namespace Includes
Public Class Child1

Public Sub ValidateIt(...)
...
WriteToLog(...)
...
End Sub
End Class
End Namespace
========================================
Namespace Includes
Public Class Child2
Public Sub WriteToLog(...)
...
End Sub
End Class
End Namespace
========================================

I know I could rearrange the structure of the above to make Parent1
instantiate Child1 which instantiates Child2 but there some other issues
making it very inconvenient to do so. Is there a way to the above without
restructuring the hiearchy ?

Cheers
Phil
 
if Child2 is only used for logging into EventLog or any log sink,
you can make Child2 method WriteToLog as static and access it from Child1.
in that case, you dont need to instantiate it.

Av.
 
Thanks for the reply - good point - that will take care of those types of
methods but I have some others that refer to variables/methods that require
to be instantiated (as they need to have there own version of for example
variables for each session)
Cheers
Phil
 
in that case, you can expose a method in Child1 which accepts an instance of
Child2 and call methods on that.

hth,
Av.
 
Back
Top