Sub Class Namespace?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • R. Nachtsturm

    #1

    Sub Class Namespace?

    Hi,

    Question (in short):
    can i somehow use the namespace tag to define that a class in its own file
    is actually the subclass (namespace wise) of another class?

    Explanation:
    for example, if I have one class named "Schema", this class should have a
    public sub class named "Table", such as:

    Namespace Test
    Public Class Schema
    Public Class Table
    End Class
    End Class
    End Namespace

    so that i could access it using: Test.Schema.Tab le

    BUT I do not want the Schema and Table class to be defined in the same file!..
    (even with regions etc it is still much harder too keep track of the classes
    if they are all in the same file)

    Elaboration:
    the above example is just that, an example, i know that it wouldn't be so
    bad to have two files in a sub namespace called Data for example (one for
    Schema and one for Table).. the problem is however that i have created my own
    global namespace which has a lot of sub namespaces but also a few select
    classes, now these classes have sub classes (a specialized settings class for
    example) but i put them into separate files to be able to keep better track
    of everything.. that however brings with it the problem that now those
    subclasses are appearing on the root my main namespace (along with their
    logical parent classes) where they obviously don't belong… what to do?

    help would be greatly appreciated to make this work!

    Thanks!
  • Larry Lard

    #2
    Re: Sub Class Namespace?

    R. Nachtsturm wrote:
    Hi,
    >
    Question (in short):
    can i somehow use the namespace tag to define that a class in its own file
    is actually the subclass (namespace wise) of another class?
    >
    Explanation:
    for example, if I have one class named "Schema", this class should have a
    public sub class named "Table", such as:
    >
    Namespace Test
    Public Class Schema
    Public Class Table
    End Class
    End Class
    End Namespace
    >
    so that i could access it using: Test.Schema.Tab le
    >
    BUT I do not want the Schema and Table class to be defined in the same file!..
    (even with regions etc it is still much harder too keep track of the classes
    if they are all in the same file)
    Using VB2005, you can have partial classes - this simply means that the
    class definition is spread across more than one file. So you could have

    (File1.vb)
    Namespace Test
    Partial Public Class Schema
    Public Class Test

    End Class
    End Class
    End Namespace

    (File2.vb)
    Namespace Test
    Partial Public Class Schema
    Public Sub New()

    End Sub
    End Class
    End Namespace

    Together, these two files define a single class Test.Schema, which
    contains a class Test.

    Before VB2005, you can't do anything like this.


    --
    Larry Lard
    larrylard@googl email.com
    The address is real, but unread - please reply to the group
    For VB and C# questions - tell us which version

    Comment

    • Chris Dunaway

      #3
      Re: Sub Class Namespace?

      R. Nachtsturm wrote:
      Explanation:
      for example, if I have one class named "Schema", this class should have a
      public sub class named "Table", such as:
      >
      Namespace Test
      Public Class Schema
      Public Class Table
      End Class
      End Class
      End Namespace
      Do you really intend a sub class? Normally the term 'subclass'
      actually refers to a derived class. What you have declared here is a
      nested class which is not quite the same thing.

      Larry has already shown you how to use partial classes. But if you
      really mean a derived class, then you don't need a partial class:


      'File #1
      Namespace Test
      Public Class Schema
      End Class
      End Namespace


      'File #2
      Namespace Test
      Public Class Test
      Inherits Schema
      End Class
      End Namespace

      Comment

      • R. Nachtsturm

        #4
        Re: Sub Class Namespace?

        Thanks for the help!

        Yes, my mistake, i meant a nested class, not a derived one :)

        so Partial Classes is what i was looking for!


        "Chris Dunaway" wrote:
        R. Nachtsturm wrote:
        >
        Explanation:
        for example, if I have one class named "Schema", this class should have a
        public sub class named "Table", such as:

        Namespace Test
        Public Class Schema
        Public Class Table
        End Class
        End Class
        End Namespace
        >
        Do you really intend a sub class? Normally the term 'subclass'
        actually refers to a derived class. What you have declared here is a
        nested class which is not quite the same thing.
        >
        Larry has already shown you how to use partial classes. But if you
        really mean a derived class, then you don't need a partial class:
        >
        >
        'File #1
        Namespace Test
        Public Class Schema
        End Class
        End Namespace
        >
        >
        'File #2
        Namespace Test
        Public Class Test
        Inherits Schema
        End Class
        End Namespace
        >
        >

        Comment

        • R. Nachtsturm

          #5
          Re: Sub Class Namespace?

          Thank you so very much!

          that was exactly what i was looking for!

          thank you!

          "Larry Lard" wrote:
          R. Nachtsturm wrote:
          Hi,

          Question (in short):
          can i somehow use the namespace tag to define that a class in its own file
          is actually the subclass (namespace wise) of another class?

          Explanation:
          for example, if I have one class named "Schema", this class should have a
          public sub class named "Table", such as:

          Namespace Test
          Public Class Schema
          Public Class Table
          End Class
          End Class
          End Namespace

          so that i could access it using: Test.Schema.Tab le

          BUT I do not want the Schema and Table class to be defined in the same file!..
          (even with regions etc it is still much harder too keep track of the classes
          if they are all in the same file)
          >
          Using VB2005, you can have partial classes - this simply means that the
          class definition is spread across more than one file. So you could have
          >
          (File1.vb)
          Namespace Test
          Partial Public Class Schema
          Public Class Test
          >
          End Class
          End Class
          End Namespace
          >
          (File2.vb)
          Namespace Test
          Partial Public Class Schema
          Public Sub New()
          >
          End Sub
          End Class
          End Namespace
          >
          Together, these two files define a single class Test.Schema, which
          contains a class Test.
          >
          Before VB2005, you can't do anything like this.
          >
          >
          --
          Larry Lard
          larrylard@googl email.com
          The address is real, but unread - please reply to the group
          For VB and C# questions - tell us which version
          >

          Comment

          Working...