Home All Groups Group Topic Archive Search About
Author
1 Aug 2006 9:25 AM
R. Nachtsturm
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.Table

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!

Author
1 Aug 2006 10:37 AM
Larry Lard
R. Nachtsturm wrote:
Show quoteHide quote
> 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.Table
>
> 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
larryl***@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Author
1 Aug 2006 4:06 PM
R. Nachtsturm
Thank you so very much!

that was exactly what i was looking for!

thank you!

Show quoteHide quote
"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.Table
> >
> > 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
> larryl***@googlemail.com
> The address is real, but unread - please reply to the group
> For VB and C# questions - tell us which version
>
Author
1 Aug 2006 1:23 PM
Chris Dunaway
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
Author
1 Aug 2006 4:05 PM
R. Nachtsturm
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!


Show quoteHide quote
"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
>
>