Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Nested Classes (after much hair pulling)

Nested Classes (after much hair pulling)

Scheduled Pinned Locked Moved Visual Basic
xmlquestionworkspace
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ray Cassick
    wrote on last edited by
    #1

    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 CConfig

    Public sub New()
    Paths = new CPaths
    Config = new CConfig

    End 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?

    R 1 Reply Last reply
    0
    • R Ray Cassick

      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 CConfig

      Public sub New()
      Paths = new CPaths
      Config = new CConfig

      End 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?

      R Offline
      R Offline
      Ray Cassick
      wrote on last edited by
      #2

      Darn folks... Didn't mean to post this twice... I kept getting errors and didn't think it posted at all. Sorry...

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups