473,471 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Class files

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
Oct 17 '07 #1
3 1240
tshad <tf*@dslextreme.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 17 '07 #2

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
tshad <tf*@dslextreme.comwrote:
>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.
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

>
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Oct 18 '07 #3
tshad <tf*@dslextreme.comwrote:
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:
<snip>
You would have 3 files:

plane.cs
SingleEnginePlane.cs
DoubleEnginePlane.cs
Yes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Hal Vaughan | last post by:
My first Java project has gotten to the point where there are so many .java and .class files that I'd like to keep them separated so I can easily keep files straight. I have my /home/me directory...
2
by: Harold Ensle | last post by:
Has anyone ever had this problem? I have been compiling servlet files, correcting them, recompiling them and seeing the changes on the next URL request. So everything was going smoothly. Suddenly...
7
by: A_StClaire_ | last post by:
hi, I'm working on a project spanning five .cpp files. each file was used to define a class. the first has my Main and an #include for each of the other files. problem is my third file...
14
by: Mick | last post by:
I wrote a C# program that interfaces with a data vendor over the web using an API they supplied and their examples in C#. Now I have another data vendor's API and example that I want to add to...
16
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
11
by: Kimmo Laine | last post by:
I'm flipping my wig here, people. I'm using classes and making each class a file. when I'm including dependet classess, I use require_once to avoid multiple declarations - yet they happen. I put...
0
by: Herman Jones | last post by:
I'm getting the following error when I build a Class Library project: Embedding manifest... Project : error PRJ0002 : Error result 1 returned from 'C:\WINDOWS\system32\cmd.exe'. It happens with...
32
by: Matias Jansson | last post by:
I come from a background of Java and C# where it is common practise to have one class per file in the file/project structure. As I have understood it, it is more common practice to have many...
5
by: Marcin Gil | last post by:
Hi! I have the code like this (obvious things like ctor/dtor removed) typedef struct _NODE { int val; int index; } Node;
2
by: yalbizu | last post by:
#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_STUDENTS=20; struct studentType { string studentFName; string studentLName;
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.