Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now