Sub Class Namespace?

G

Guest

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!
 
L

Larry Lard

R. Nachtsturm said:
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.
 
C

Chris Dunaway

R. Nachtsturm said:
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
 
G

Guest

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top