Code Organization: utility methods in a complex class

I've got a complex class object that has "primary" methods and "utility" methods.

I'd like to separate out the utility methods so I don't see them in the VS2005 drop down of methods for the class.

I don't want to have to instantiate a separate class to get at the utility methods, and the utility methods need to access a set of private variables for the class.

I was thinking of doing a sub class "MU" that would inherit the main class, and calling the utilities from that, as in:

Me.MU.Util1   or   MyClass.MU.Util1

instead of

Me.Util1    or   MyClass.Util1

But that doesn't seem to work.

Any ideas on how to accomplish the result I'm looking for?    Or reasons why it's not possible?


LVL 2
codequestAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian CroweDatabase AdministratorCommented:
create a class with shared methods as your utility class.  That way you don't have to instantiate it.
0
codequestAuthor Commented:
Thanks for the input.  I've done that in other instances.  Can that class inherit from the "main" class, in order to get at the private variables?
 
0
GlomCommented:
No, it can't, because shared Methods can only access shared attributes and variables.
You can then declare your variables as Friend and pass the instance of the class containing these variables to the shared methods of your Utility class.

Your Utility class :

Public NotInheritable Class Utility

' To force the use as a utility class
Private Sub New
End Sub

Public Shared Sub Test(instance as primaryClass)
    ' myVariable declared as Friend in the PrimaryClass
    instance.myVariable = 4
End Sub

End Class

Bye
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
codequestAuthor Commented:
Thanks for input.   I can see there are tradeoffs here.  

One thing I did do was rename the methods to start with "Ut_" so that they sort to the bottom of the methods list.

Grazie!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.