Class files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    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


  • Jon Skeet [C# MVP]

    #2
    Re: Class files

    tshad <tfs@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 - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    • tshad

      #3
      Re: Class files


      "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
      news:MPG.218082 cd3516a803551@m snews.microsoft .com...
      tshad <tfs@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 _numberOfEngine s;
      public int numberOfWheels = 3;
      public int NumberOfEngines
      {
      get
      {
      return _numberOfEngine s;
      }
      set
      {
      _numberOfEngine s = value;
      }
      }
      public string TailNumber
      {
      get
      {
      return tailNumber;
      }
      set
      {
      tailNumber = value;
      }
      }
      }

      public class SingleEnginePla ne : Plane
      {
      public SingleEnginePla ne()
      {
      _numberOfEngine s = 1;
      }
      }

      public class DoubleEnginePla ne : Plane
      {
      public DoubleEnginePla ne()
      {
      _numberOfEngine s = 2;
      }
      }
      *************** *************** *************** **

      You would have 3 files:

      plane.cs
      SingleEnginePla ne.cs
      DoubleEnginePla ne.cs

      Thanks,

      Tom

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

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Class files

        tshad <tfs@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
        SingleEnginePla ne.cs
        DoubleEnginePla ne.cs
        Yes.

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

        Comment

        Working...