.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Classes, Methods and Performance
 

Classes, Methods and Performance

Is it better to have a fewer number of methods in a certain class? In other words, if I have a class that keeps growing should I consider splitting it into several?

The Samster
The Samster wrote:

Is it better to have a fewer number of methods in a certain class? In other words, if I have a class that keeps growing should I consider splitting it into several?

Simple answer: no, don't split a class just because it has too many methods.

Real answer; you should be designing classes that are cohesive and decoupled. By just adding methods to a class over time it sounds like there is no design. Doing something like that means your class will not be cohesive and if you split a class up just to avoid many methods you've got highly coupled classes. You'll have a hard time maintaining classes like that.

Peter Ritchie
The Samster wrote:

Is it better to have a fewer number of methods in a certain class? In other words, if I have a class that keeps growing should I consider splitting it into several?

Simple answer: no, don't split a class just because it has too many methods.

Real answer; you should be designing classes that are cohesive and decoupled. By just adding methods to a class over time it sounds like there is no design. Doing something like that means your class will not be cohesive and if you split a class up just to avoid many methods you've got highly coupled classes. You'll have a hard time maintaining classes like that.

Peter Ritchie

You can use google to search for other answers

Custom Search

More Threads

• error when creating a directory
• Run Windows Application From Windows Service?
• Writing strings to a local db using a sql command inserts trailing blanks
• Runtime discovery of assembly? Assembly API?
• dynamic directory
• Adding Features to Existing Programs
• Calculating Remaining Time
• folder security in web application
• Multi-assembly configuration
• Rename machine Name which is in Domain