Solved

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

Posted on 2013-01-23
3
844 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

763 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