Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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