Does it matter if one of my classes is very big?

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi I am working on a web application which will be accessed by
thousands of visitors per day, so speed and performance is crucial to
the application.

One of the business logic classes in my project is now rather big (350
lines) and expected to keep growing further and further...

It is used in nearly all the webforms.

Does its size affect peformance in anyway?

Should I be creating more but smaller classes rather than putting most
of my methods into one class?

Very interested in what people have to say on this.

Kind regards,

Steve.
 
From performance perspective it is fine. Breaking a big class into smaller
ones may be beneficial from the design and maintainability perspective.
 
Steve said:
Hi I am working on a web application which will be accessed by
thousands of visitors per day, so speed and performance is crucial to
the application.

One of the business logic classes in my project is now rather big (350
lines) and expected to keep growing further and further...

It is used in nearly all the webforms.

Does its size affect peformance in anyway?

Should I be creating more but smaller classes rather than putting most
of my methods into one class?

Very interested in what people have to say on this.

Kind regards,

Steve.

Don't optimize until you need to, and then be smart about your
optimization. The size of the class (and 350 lines doesn't sound
horrendously big to me) won't have too much effect, unless you're
saying that the class contains many different and disparate methods
which are used differently by the different pages. In that case, good
design would separate the class out into smaller, more cohesive
classes. If you're not familiar with the terms "coupling" and
"cohesion", look them up for advice on how to structure your classes.

Now, onto the optimization. The best way to optimize is to use a
profiler. If you're in VS2005, I believe there is a built in profiler
(not sure which editions - fairly sure it isn't in Express). At work,
I'm working in VS2003 which doesn't have one, so I use a third party
profiler (ANTS, not sure if there are others). Use it to find your
hotspots, and optimize those - it's a lot easier than trying to "guess"
where you can gain performance (both processor- and memory-wise).

Damien
 
Steve, here's the "thing":

1) 350 lines is very small. Assemblies are loaded into the appDomain and
stay there, and they are compiled, so having an assembly containing multiple
classes that originally had thousands of lines of code each before JITing is
not a big deal.

2) From a performance standpoint, you may be better off with a single
assembly containing more code, than multiple assemblies with less code each.

3) As already mentioned, you can optimize code by observing best practices
coding style and using profiling tools.

Peter
 
Back
Top