Question nested objects

garths

New member
Joined
Sep 30, 2008
Messages
3
Programming Experience
Beginner
I am new to the .NET development environment and am having a hard time understanding creating nested objects.

I would like is to create classes that expose only the nested objects and not the classes, like the following:

meter.voltage.dc

When I create the classes however I can not figure out how to hide the nested classes. So what I have is:

VB.NET:
Public class meter_
  Public class voltage_
    Public class dc_

    end class
    Public dc as dc_
    Public sub new()
      dc = new dc_
    end sub
  end class
  Public voltage as voltage_
  Public sub new()
    voltage = new voltage_
  end sub
end class

So it shows meter.voltage_ class as well as meter.voltage object.

How can I hide the meter.voltage_ class?

Thanks in advance.
 
Last edited by a moderator:
vis781: Thank you for the quick response.

I tried declaring the voltage_ class as private previously but the compiler gives me an error saying that I can not expose type voltage_ through class meter_.

There must be something very fundamental that I am missing.

Thanks.
 
VB.NET:
Public voltage as voltage_

Is your problem line. You can't expose a private class through a public member variable through a public class.
My fault didn't read the post properly. You can do this using an interface. Create an interface and implement it in the volatage class then expose the interface through a public property in the meter_ class.

Bit like this...

VB.NET:
Public Class meter_

    Public Interface IvoltageInterface
        Sub someVoltage()

    End Interface

    Public Sub New()
        voltage = New voltage_
    End Sub

    Private voltage As voltage_

    Public ReadOnly Property METERVOLTAGE() As IvoltageInterface
        Get
            Return Me.voltage
        End Get
    End Property



    Private Class voltage_
        Implements IvoltageInterface


        Public dc As dc_
        Public Sub New()
            dc = New dc_
        End Sub


        Public Sub someVoltage() Implements IvoltageInterface.someVoltage
            'do something
        End Sub

    End Class
    Public Class dc_

    End Class


End Class
 
Back
Top