Link to home
Start Free TrialLog in
Avatar of Mr_Fulano
Mr_FulanoFlag for United States of America

asked on

Adding addtional Modules to a C# Solution.

Hi, I'm using MS VS2010, C#.NET. I currently have an application with a lot of methods all rolled up above the code for my Controls. I'd like to organize my code-behind in a more intuitive manner (at least intuitive for me) and be able to add Modules (additional Tabs) where I can put all the code that is general math related into one Tab and another Tab for all the code dealing with hexadecimal manipulations, etc. I guess I can use Namespaces, but is that the best approach. I recall in VB.NET I was able to add Modules to the application and have different modules (i.e. pages , Tabs) for different code types.

Is that possible in C#, if so how would I do that, and if not what is a better approach other than to have all my code on one page all rolled up?

Thanks,
Fulano
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you are trying to make a class easier to read use regions eg
#region Math Code

//Methods related to Maths here

#endregion

Open in new window


Visual Studion allows to collapse regions and so makes it far easier to navigate your code to find what you are after.

Michael
Avatar of Mr_Fulano

ASKER

Hi Michael74, yes...by "rolled up" in my original post, I mean I have them all in regions, but its still messy! I was hoping to spread things out a bit and have designated areas for certain types of code.

Thanks,
Fulano
Hi Kaufmed, good suggestions. I'll give that approach a try and see where I go with it.

Thanks,
Fulano
I don't like modules. Really, they exist just for backward compatibility with VB6 and prior.

I a class becomes too large - try to re-factor to separate classes. Check that no business logic in a presentation layer - move it to business classes.

Idea with regions is also good - I use it all the time.
I personally use a combination. As noted above keeping presentation and business logic seperated is always a good idea but I like to use regions to seperate code into sections eg

Public Varaibles
Private Variables
Constructors
Button Click Events
etc..

Fulano
If you are finding that some regions are getting out of hand then look at seperating these regions out into new classes. Static classes are very handy for this.

Michael
Hi Michael, regions is what I use now and its a bit too messy for my taste. Regions work for small areas of code, but when you begin to have 4 or 5 different methods within that region, then its too hard to keep under control.

I was thinking of Classes, but I guess the problem I'm struggling with is that a Class can be instantiated into an Object, so I'm thinking my MathClass can be instantiated into a MathClass Object, which wouldn't make any sense given that its a Class without a constructor (well...all Classes have a default constructor that really doesn't do anything), and that Class is full of methods.

Is that a good idea....?

Thanks,
Fulano
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent....this is what I needed to understand. -- Static Classes is what will help me refactor my code. Thank you both!