Hüseyin Dalyan :
I have 3 Classes.
1 - araTrendClass
2 - driverClass
3 - sayfaYardimcisiClass
I called and used driverClass inside my araTrendClass.
But I want to use driverClass inside another class from inside my araTrendClass.
So, I want to call driverClass not directly.
I want to call it from inside my araTrendClass.
How can I access this class from another class?
Caius Jard :
Pass the driverClass
instance to the class that will use it, perhaps as a constructor argument:
Public Class SayfaYardimcisiClass
Private _driverClass as DriverClass
Public Sub New(driver As DriverClass)
_driverClass = driver 'hold on to reference we are given
End Sub
Public Sub DoSomething()
Console.WriteLine(_driverClass.Name) 'the araTrendClass code class will set it to "hello"
_driverClass.DoSomething()
End Sub
End Class
Public Class AraTrendClass
Private _topLevelDriverClass as New DriverClass
Public Sub DoThatThing()
_topLevelDriverClass.Name = "hello"
'give this instance of DriverClass to the new SafayaYardimcisiClass
Dim syc as New SayfaYardimcisiClass(_topLevelDriverClass)
syc.DoSomething() 'will print "hello"
End Sub
End Class
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=293410&siteId=1