Rule #23
Do you use one class per file?
  v3.0 Posted at 20/10/2010 7:56 PM by system

Each class definition should live in its own file.

Reasons:

Easy to locate class definitions outside the Visual Studio IDE (e.g. SourceSafe, Windows Explorer)

The only exception should be - classes that collectively forms one atomic unit of reuse should live in one file. For example:

class MyClass

{
     ...
}

class MyClassAEventArgs
{
    ...
}

class MyClassBEventArgs
{
    ...
}

class MyClassAException
{
    ...
}

class MyClassBException
{
    ...
}
Bad example - 1 project, 1 file.
 


Related rules