Leaders snarfblam Posted April 25, 2005 Leaders Posted April 25, 2005 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. Quote [sIGPIC]e[/sIGPIC]
thenerd Posted April 25, 2005 Posted April 25, 2005 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 Quote
Leaders snarfblam Posted April 25, 2005 Author Leaders Posted April 25, 2005 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. Quote [sIGPIC]e[/sIGPIC]
HJB417 Posted April 25, 2005 Posted April 25, 2005 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. Quote
Leaders snarfblam Posted April 26, 2005 Author Leaders Posted April 26, 2005 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. Quote [sIGPIC]e[/sIGPIC]
*Experts* mutant Posted April 26, 2005 *Experts* Posted April 26, 2005 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? Quote
Leaders snarfblam Posted April 26, 2005 Author Leaders Posted April 26, 2005 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. Quote [sIGPIC]e[/sIGPIC]
HJB417 Posted April 26, 2005 Posted April 26, 2005 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. Quote
Leaders snarfblam Posted April 26, 2005 Author Leaders Posted April 26, 2005 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.