Solved

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

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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