Nested Classes (after much hair pulling)
-
Ok, I want to create an object hierarchy within my application that will take care of holding some common settings as an alternative to using global vars. I also want this to be a holding area for the application level configuration info that will be read in from a few XML configuration files. My intent is to serialize this data to an XML file latter and pass the file onto some external plug in type components so they can parse through it as they need to and grab what ever configuration settings they need. The basic gist of what I am looking for is this.... I want to have a parent class (App) to contain a few nested classes (Paths, Config, etc...), and each of these nested classes to have some properties internal to them. My intent here is to be able to create one instance of the parent class and get access to all the members of the child classes as so:
App.Paths.Path1
...
App.Config.Setting1
...Now, what I wanted (expected to be able to do) was:
Class App
Public Paths as CPaths
Public Config as CConfigPublic sub New()
Paths = new CPaths
Config = new CConfigEnd sub
Protected Class CPaths
Private \_Path1 as string Protected sub New() ... Protected Readonly Property Path1 as String Get Return \_Path1 End Get End Property
End Class
Protected Class CConfig
Private \_Setting1 as string Protected sub New() ... Protected Readonly Property Setting1 as String Get Return \_Setting1 End Get End Property
End Class
End Class
Instead what I HAD to do was make each one of the nested classes public because I could not declare a public instance of a protected nested class in the parent class constructor!!! While this does appear to work, it also seems to allow a developer to bypass my parent class and directly create instances of my nested classes. IE: they will be able to declare as follows:
Dim objAppPaths As New App.CPaths
This really seems to be counter productive to building this hierarchy in the first place. Am I missing something here?
-
Ok, I want to create an object hierarchy within my application that will take care of holding some common settings as an alternative to using global vars. I also want this to be a holding area for the application level configuration info that will be read in from a few XML configuration files. My intent is to serialize this data to an XML file latter and pass the file onto some external plug in type components so they can parse through it as they need to and grab what ever configuration settings they need. The basic gist of what I am looking for is this.... I want to have a parent class (App) to contain a few nested classes (Paths, Config, etc...), and each of these nested classes to have some properties internal to them. My intent here is to be able to create one instance of the parent class and get access to all the members of the child classes as so:
App.Paths.Path1
...
App.Config.Setting1
...Now, what I wanted (expected to be able to do) was:
Class App
Public Paths as CPaths
Public Config as CConfigPublic sub New()
Paths = new CPaths
Config = new CConfigEnd sub
Protected Class CPaths
Private \_Path1 as string Protected sub New() ... Protected Readonly Property Path1 as String Get Return \_Path1 End Get End Property
End Class
Protected Class CConfig
Private \_Setting1 as string Protected sub New() ... Protected Readonly Property Setting1 as String Get Return \_Setting1 End Get End Property
End Class
End Class
Instead what I HAD to do was make each one of the nested classes public because I could not declare a public instance of a protected nested class in the parent class constructor!!! While this does appear to work, it also seems to allow a developer to bypass my parent class and directly create instances of my nested classes. IE: they will be able to declare as follows:
Dim objAppPaths As New App.CPaths
This really seems to be counter productive to building this hierarchy in the first place. Am I missing something here?
Darn folks... Didn't mean to post this twice... I kept getting errors and didn't think it posted at all. Sorry...