Referencing calling class

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have two distinct classes A & B. I am using class B from within Class A
as follows;

Public Class clsClassA

Friend ClassB As new ClassB

Public Sub New()
ClassB = new ClassB
End Sub
....
End Class

My question is how can I refer to instance of Class A which called Class B,
from within Class B in this scenario?

Thanks

Regards
 
* "John said:
I have two distinct classes A & B. I am using class B from within Class A
as follows;

Public Class clsClassA

Friend ClassB As new ClassB

Public Sub New()
ClassB = new ClassB
End Sub
...
End Class

My question is how can I refer to instance of Class A which called Class B,
from within Class B in this scenario?

Pass a reference to the calling class.
 
John,
A quick code example?

The "easiest" way is to pass ClassA as a parameter to ClassB's constructor,
something like:

Public Class ClassA

Private m_b As ClassB

Public Sub New()
m_b = new ClassB(Me)
End Sub

End Class

Public Class ClassB

Private m_a As ClassA

Public Sub New(ByVal a As ClassA)
m_a = a
End Sub

End Class
Sorry vb6 background. Not strong on classes.
I would recommend Robin A. Reynolds-Haertle's book "OOP with Microsoft
Visual Basic.NET and Microsoft Visual C#.NET" from MS Press, she does a very
good job of explaining the How of OOP in VB.NET. However! she does not
necessarily cover the Why of OOP.

Hope this helps
Jay

John said:
A quick code example? Sorry vb6 background. Not strong on classes.

Thanks

Regards

Class
Class
 
Thanks.

'Why' is overrated anyway. :) Geek's point of view.

Regards


Jay B. Harlow said:
John,
A quick code example?

The "easiest" way is to pass ClassA as a parameter to ClassB's constructor,
something like:

Public Class ClassA

Private m_b As ClassB

Public Sub New()
m_b = new ClassB(Me)
End Sub

End Class

Public Class ClassB

Private m_a As ClassA

Public Sub New(ByVal a As ClassA)
m_a = a
End Sub

End Class
Sorry vb6 background. Not strong on classes.
I would recommend Robin A. Reynolds-Haertle's book "OOP with Microsoft
Visual Basic.NET and Microsoft Visual C#.NET" from MS Press, she does a very
good job of explaining the How of OOP in VB.NET. However! she does not
necessarily cover the Why of OOP.

Hope this helps
Jay
 
John,
??

Without the "why" why practice OOA, OOD, and OOP?

If the "Why" is overrated, then I don't see that you would bother with
Classes & OOP!

OOA = Object Oriented Analysis
OOD = Object Oriented Design
OOP = Object Oriented Programming

Just a thought
Jay
 
OK, what I meant was, I have been to access, vb4,5,6 etc. They do the job
for me too, db apps. So I had been relatively comfortable with them and
probably not that much until now with vb.net even though it is OO. Point
being it slightly gets to one's head if you miss things here and there that
make your job difficult and all the time it is OO. I would rather they put
those drag drop db stuff as soon as pos and I am happy if my db app gets
done, on time, OO or no OO.

Just my thoughts...
 
Back
Top