Solved

C# - Is one class per class file the norm?

Posted on 2013-01-23
3
854 Views
Last Modified: 2013-01-23
One of my subs likes to create 2 or 3 classes per class file (CS file). In contrast, I tend to create one class per class file (CS file). What's the industry norm?
0
Comment
Question by:jdana
[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
3 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 170 total points
ID: 38812509
Generally one class per file but can depends on the use of the class, if it represents and object in the business layer then one class per file, however utlility methods may be separated into separate classes but be contained in one file.
0
 
LVL 3

Assisted Solution

by:contactnaeem
contactnaeem earned 170 total points
ID: 38812562
As general rule and for clean code follow single class single responsibility and single file rule. I know many developers (including me) tends to write multiple classes in one file but reason behind this is that sometimes we are lazy and otherr times we are not  thinking through about writing clean code and we end up with ugly, culuttered and difficult to support/understand code. In a large project any new developer will not be able to locate a class with file name but he has to actually open a file to see what classes are there.
I will suggest you to even go one step further and think about writing clean, single responsibility methods/functions.
0
 

Author Closing Comment

by:jdana
ID: 38812596
Thanks guys.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 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