473,378 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Child classes calling one anothers methods

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

Nov 18 '05 #1
3 1120
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.
"Horace" <so*****@nowhere.com> wrote in message
news:tU***************@nnrp1.ozemail.com.au...
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

Nov 18 '05 #2
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
"avnrao" <av*@newsgroups.com> wrote in message
news:uI**************@tk2msftngp13.phx.gbl...
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.
"Horace" <so*****@nowhere.com> wrote in message
news:tU***************@nnrp1.ozemail.com.au...
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


Nov 18 '05 #3
in that case, you can expose a method in Child1 which accepts an instance of
Child2 and call methods on that.

hth,
Av.
"Horace" <so*****@nowhere.com> wrote in message
news:Vk***************@nnrp1.ozemail.com.au...
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
"avnrao" <av*@newsgroups.com> wrote in message
news:uI**************@tk2msftngp13.phx.gbl...
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.
"Horace" <so*****@nowhere.com> wrote in message
news:tU***************@nnrp1.ozemail.com.au...
> 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
>
>
>



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: pablo | last post by:
Dear NewsGroupers, I am relatively new to OOP and cannet get my head around this problem. I have two classes. Class Child extends Parent. There is no constructor for the Child class. So when I...
16
by: Suzanne Vogel | last post by:
Hi, I've been trying to write a function to test whether one class is derived from another class. I am given only id's of the two classes. Therefore, direct use of template methods is not an...
9
by: Martin Herbert Dietze | last post by:
Hello, I would like to implement a callback mechanism in which a child class registers some methods with particular signatures which would then be called in a parent class method. In...
2
by: Andrea Gavana | last post by:
Hello NG, this may seem a stupid (or even impossible) question, but my knowlegde of Python is quite limited. I have basically a simple graphical user interface that contains a Panel, another...
4
by: james | last post by:
I have a custom UserControl, which can have many sub class levels derived from it. I want to be able to discover all the components at Load time, but the only components I can see from the base...
10
by: Barbara Alderton | last post by:
I am working with SharePoint 2003. I am using (using C#) an existing webpart as a child control (server control). I need to access/manipulate the HTML that the control outputs prior to rendering...
0
by: Carlitos | last post by:
Hi there, I apologize if it is not the right forum to post this question, but it has to do with C#, HTML and javascript altogether. I programmed a windows form custom control in C# which...
9
by: Allan Ebdrup | last post by:
I would like to use reflection to find all classes that inherit from my current class, even if they are in another assembly I want to find them if the current project has a reference to that...
1
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
The code below is pretty simple. Calling Talker() in the parent returns "Parent", and calling Talker() in the child returns "Child". I'm wondering how I can modify the code so that a call to the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.