I am trying to figure out the best approach for setting and getting properties in a nested class I am creating.
I have a class, Car which has a nested class ControlPanel and want to make the properties of the Control Panel only accessible to the Car and Control Panel class.
(ie: not within the assembly or namespace and not within the application the class library will be going to be used)… I have changed the class access properties to friend, protected friend, private, public, but any combination is not matching my expected results.
I want to change the properties in the Drive() Sub of a class as shown below.
Any thoughts?
Public Class Car
Dim cp As New ControlPanel
Public Class ControlPanel
Private _Speedometer As Integer = 0
Private _Odometer As Integer = 0
Public Property Speedometer() As Integer
Get
Return _Speedometer
End Get
Protected Set(ByVal value As Integer)
_Speedometer = value
End Set
End Property
Public Property Odometer() As Integer
Get
Return _Odometer
End Get
Protected Set(ByVal value As Integer)
_Odometer = value
End Set
End Property
End Class
Public Sub Drive()
cp.Odometer = 76323
co.Speedometer = 86
End Sub
End Class
You can do it like this:
It uses a private interface nested in the
Carclass with privately implemented and aliased members inControlPanel. This way, onlyCarcan access the interface members.