Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Organizing Code

Posted on 2003-12-03
7
Medium Priority
?
371 Views
Last Modified: 2010-04-16
I'm designing a class, and once again I'm faced with the old problem: When fully implemented, the length of the class (lines of code) will be very large. Perhaps 1500 lines of code.

So the question becomes: How can I somehow divide/partition/organize the code so that it is partitioned into smaller chunks?

I've had this picture in my mind that if you can organize information into a tree/hierarchy, with each level of the three having hopefully <= 10 nodes, that information seems readable. It's when you nodes of the tree with, perhaps 40 children, that things are very hairy.

Where this comes into code is that I wish you could design code into hierarchies. What is the appropriate way to do this? What do you do when you have a class that has, say 10 data members, but has a function within it that is 1000 lines long and a few other functions totalling 500 lines? You can break the 1000 line long function into parts so that each part is on average say 75 lines long, but then you have this long list of component functions which are unorganized. And your .CS file is still huge.

I guess I'm just a bit frustrated with organizing my code, and I wish I could:

- Not have any .CS files that are big (>500 lines)
- Organize code into hierarchies

I'm rambling.

Thoughts?
0
Comment
Question by:daniel_bigham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 450 total points
ID: 9872916
Use regions. I always divide my classes to regions like: publuc functions, public members, event handlers, etc. It's up yo you to decide the level and content of this hierarchy. It may depend also on class type: form, control, generic class etc.
Use helper classes when possible.
Use Class View as much as possible - when you access your code from Class View, you don't care about it's length.

0
 
LVL 1

Author Comment

by:daniel_bigham
ID: 9874754
Can you give me an example of what a helper class is and how it's used?
0
 
LVL 7

Expert Comment

by:jj819430
ID: 9878535
What I have found to be useful is to break up the classes.

Say you are doing something simple like a linked list class.

Well you would have the Root Class = Linked List.

You would have Root's children = Add to Linked list, Delete from Linked List, Sort Linked List, Search Linked list .... Etc.


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Assisted Solution

by:shahpaulin
shahpaulin earned 150 total points
ID: 9883635
I am elaborating on regions.
I use them and they create a lot of space on the screen and help to organize my codes.

you just write
#region "MyClass"

======ur relevant code=====

#endregion "MyClass"

The above statements will cause the code between *regions* to drop down into a tree and create a node by name "MyClass", which you can expand and close to see the code in between.

One other feature in .net while writing big codes and working with many files in the same project is TODO keyword.

While writing a code, if you come across a loop/funcion which you want to deal with later, just
write
           'TODO write up the connection
And you can go into Menu->View->Show Tasks, it will give you a listing of all *TODO*'s in your project and when u click it will directly take you to that place.  its a very cool feature which i find very helpful.

Hope this helps.

-Paulin
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 450 total points
ID: 9883730
Helper class is just class created to solve some subtasks. For example, if you have some string-processing functions in your class:

string s;
Operation1(s);
Operation2(s);

...

you may decide to vreate another class for these operations:

string s;
StringHandler h;
h.Operations(s);
h.Operation2(s);


0
 
LVL 1

Author Comment

by:daniel_bigham
ID: 9884259
But a helper class won't have access to the implementation of the class its helping?
0
 
LVL 1

Assisted Solution

by:bakobako
bakobako earned 150 total points
ID: 9885270
Other than using regions, which I find really helpful, the rest depends on how you decide to architect the class. The use of helper classes must be tempered by when they make since to use them.
 You can also look to see if anything in the methods breaks out logically as separate classes, or structures. If you look at it you may see different aspects of what you are doing break out into a separate class. But all of this depends on what you are doing. The regions are the only things I can think of which would help make things more bearable if the architecture just doesn’t break down any further.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question