Class files

T

tshad

I am starting to work with abstract Classes and Interface in VS 2003 and
was wondering which is the best way to set the files up.

If I have something like:

abstract user class (could also just be a class that would be the base
class)
employee inheriting user class
applicant inheriting user class
interface something

Is it best to have:

user.cs
employee.cs
applicant.cs
something.cs

or

have them all in the same file, such as:

user.cs

Thanks,

Tom
 
J

Jon Skeet [C# MVP]

tshad said:
I am starting to work with abstract Classes and Interface in VS 2003 and
was wondering which is the best way to set the files up.

If I have something like:

abstract user class (could also just be a class that would be the base
class)
employee inheriting user class
applicant inheriting user class
interface something

Is it best to have:

user.cs
employee.cs
applicant.cs
something.cs

or

have them all in the same file, such as:

user.cs

In my experience, it's *much* better to have one top-level type per
file. The one exception I sometimes have to this is delegates, which I
sometimes lump together in Delegates.cs.
 
T

tshad

Jon Skeet said:
In my experience, it's *much* better to have one top-level type per
file. The one exception I sometimes have to this is delegates, which I
sometimes lump together in Delegates.cs.

So for this:

************************************
public abstract class Plane
{
public string tailNumber;
protected int _numberOfEngines;
public int numberOfWheels = 3;
public int NumberOfEngines
{
get
{
return _numberOfEngines;
}
set
{
_numberOfEngines = value;
}
}
public string TailNumber
{
get
{
return tailNumber;
}
set
{
tailNumber = value;
}
}
}

public class SingleEnginePlane : Plane
{
public SingleEnginePlane()
{
_numberOfEngines = 1;
}
}

public class DoubleEnginePlane : Plane
{
public DoubleEnginePlane()
{
_numberOfEngines = 2;
}
}
***********************************************

You would have 3 files:

plane.cs
SingleEnginePlane.cs
DoubleEnginePlane.cs

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top