472,119 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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.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!
Aug 1 '06 #1
4 1616
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
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Aug 1 '06 #2
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

Aug 1 '06 #3
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

Aug 1 '06 #4
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.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
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Aug 1 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by marco_segurini | last post: by
reply views Thread by keith bannister via .NET 247 | last post: by
14 posts views Thread by Lee Franke | last post: by
6 posts views Thread by ryan.d.rembaum | last post: by
16 posts views Thread by tshad | last post: by
6 posts views Thread by Nikola | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.