Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted
Is there a way to declare a nested class without actually putting it within the declaration of the outer class in your code? This is leading to really cluttered code for me.
[sIGPIC]e[/sIGPIC]
Posted

Would something like this work?

Public class class1

public thingy as class2

public sub new()
thingy = new class2
end sub

end class

Public class class2

public sub somethinguseful()
messagebox.show("ANNOY")
end sub

end class

  • Leaders
Posted

No, that is not a nested class. That's simply class instantiated within another class.

 

  Class A
      Public Member As Integer
'
      Private Class B
          Public Member As Integer
      End Class
  End Class

 

In such a case, class B can only be instantiated by class A. Were class B declared publicly, anyone could instantiate class B, but would have to use the syntax [New A.B] as opposed to [New B].

 

I need to use nested classes to provide private classes and organize object models. But when my classes get large and complex, nested classes cause clutter.

[sIGPIC]e[/sIGPIC]
Posted
Is there a way to declare a nested class without actually putting it within the declaration of the outer class in your code? This is leading to really cluttered code for me.

 

No though it might be easier in managed c++ becuase it has headers and source file.

  • Leaders
Posted
No though it might be easier in managed c++ becuase it has headers and source file.

 

Certainly true, however, that isn't much of an option for me seeing as I am very rusty on what little (unmanaged) C++ I know.

 

And I'm betting that the answer to my question is "no," but I am hoping that I'm wrong because my code is starting to give me a headache.

[sIGPIC]e[/sIGPIC]
  • *Experts*
Posted

Not possible right now but will be in the future with partial classes (not future if you want to use beta software which you can't distribute :)).

Did you consider using code Regions?

  • Leaders
Posted
Did you consider using code Regions?

 

Class definitions are collapsable anyways. The problem is that I am editing all of the classes at the same time because they all relate so closeley to eachother, so I can't collapse them. If I could click a tab to open a different .vb file it wouldn't be so confusing, but as it is now, I have many functions between the different classes with similar names and the massive amount of functions is hurting my head.

[sIGPIC]e[/sIGPIC]
Posted
of the hundereds of classes I've created using the .net framework, the number of nested classes I've created, I can count using 1 hand and it's never caused me a headache. I think you may need to consider a design change if you find nested classes to be cumbersome.
  • Leaders
Posted

I'm designing an object model where nested classes are very appropriate. The nested classes should only ever be used in conjuntion with the class in which it is nested in, just like the ListView class, which nests ListViewItems, ListViewItemCollection, CheckedIndexCollection, CheckedListViewItemCollection, ColumnHeaderCollection, SelectedIndexCollection, and SelectedListViewItemCollection.

 

I think it might give me more of a headache to have so many classes all in the same namespace. Imagine if Windows Forms did not use nested classes. Using nested classes is far from cumbersome, but I can't say the same for their implementation in VB.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...