Inheritance / file locations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johnny van Cadsand

    #1

    Inheritance / file locations

    Hi,

    I know how inheritance works.
    But do i have to put all the inherited class files in the same
    directory as the class file which inherits is in?? (VB.NET)

    When i have a baseclass which i want to use in different solutions, then
    i add the class to a solution. The IDE copies the file to the other
    solution folder and i have 2 copies of the same class file.

    The idea of inheritance is reusable code, but when i have 2 identical
    files on different locations do i have to edit them both when something
    changes to my baseclass???

    Should i use a dll? I know it's a possible solution but not the most nice
    one.
    Why hasn't MS thought about this?
    Has anyone an explanation?

    --

    =============== =============== =============== =============== ==
    Johnny van Cadsand news ( ) cadsand ! demon ! nl

    ..:: Up to the Sky and Back ::..
  • Marina

    #2
    Re: Inheritance / file locations

    They have thought about it. I don't know if you have.

    If you add an existing class to a solution, all that means is that VS.NET
    copies the file. This has nothing to do with code reusability. Because
    then, anyone who wants to use your class, would need your source code??

    You are supposed to compile the base class into a DLL, and then use the dll
    in other projects. It is the perfect solution - and certainly a lot better
    then having multiple copies of the source all over the place or having to
    have the source code for a class in order to inherit from it. What company
    is going to write a control, if the only way anyone can use it is to have
    their source code?

    "Johnny van Cadsand" <news@nospam.ca dsand.demon.nl> wrote in message
    news:Xns9591D2B 76D350newscadsa nddemonnl@216.1 68.3.44...[color=blue]
    > Hi,
    >
    > I know how inheritance works.
    > But do i have to put all the inherited class files in the same
    > directory as the class file which inherits is in?? (VB.NET)
    >
    > When i have a baseclass which i want to use in different solutions, then
    > i add the class to a solution. The IDE copies the file to the other
    > solution folder and i have 2 copies of the same class file.
    >
    > The idea of inheritance is reusable code, but when i have 2 identical
    > files on different locations do i have to edit them both when something
    > changes to my baseclass???
    >
    > Should i use a dll? I know it's a possible solution but not the most nice
    > one.
    > Why hasn't MS thought about this?
    > Has anyone an explanation?
    >
    > --
    >
    > =============== =============== =============== =============== ==
    > Johnny van Cadsand news ( ) cadsand ! demon ! nl
    >
    > ..:: Up to the Sky and Back ::..[/color]


    Comment

    • Johnny van Cadsand

      #3
      Re: Inheritance / file locations

      Marina wrote :
      [color=blue]
      > They have thought about it. I don't know if you have.
      >
      > If you add an existing class to a solution, all that means is that
      > VS.NET copies the file. This has nothing to do with code reusability.
      > Because then, anyone who wants to use your class, would need your
      > source code??
      >
      > You are supposed to compile the base class into a DLL, and then use
      > the dll in other projects. It is the perfect solution - and certainly
      > a lot better then having multiple copies of the source all over the
      > place or having to have the source code for a class in order to
      > inherit from it. What company is going to write a control, if the
      > only way anyone can use it is to have their source code?
      >[/color]
      Alright...

      That's what i thought but it looked strange to me that file copied...

      But indeed, you don't need the source!!

      Thanks...



      --
      =============== =============== =============== =============== ==

      Johnny van Cadsand news ( ) cadsand ! demon ! nl

      ..:: Up to the Sky and Back ::..

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Inheritance / file locations

        "Johnny van Cadsand" <news@nospam.ca dsand.demon.nl> schrieb:[color=blue]
        > I know how inheritance works.
        > But do i have to put all the inherited class files in the same
        > directory as the class file which inherits is in?? (VB.NET)
        >
        > When i have a baseclass which i want to use in different solutions, then
        > i add the class to a solution. The IDE copies the file to the other
        > solution folder and i have 2 copies of the same class file.[/color]

        Add the class to one project of type "Class Library" and reference this
        project (DLL) from the other projects.
        [color=blue]
        > Should i use a dll? I know it's a possible solution but not the
        > most nice one.[/color]

        Why not? Sure, for a single class, it doesn't make much sense, but if there
        is a set of classes I would add them to a class library.

        VS.NET provides a way to reference the file instead of creating a copy of
        it: "Project" -> "Add Existing Item..." -> Change the button labeled "Open"
        to "Reference File" and press it.

        --
        Herfried K. Wagner [MVP]
        <URL:http://dotnet.mvps.org/>

        Comment

        • Larry Serflaten

          #5
          Re: Inheritance / file locations


          "Johnny van Cadsand" <news@nospam.ca dsand.demon.nl> wrote
          [color=blue]
          > I know how inheritance works.[/color]

          OK, now concentrate on learning how to use the tool.... ;-)
          [color=blue]
          > But do i have to put all the inherited class files in the same
          > directory as the class file which inherits is in?? (VB.NET)[/color]

          No.

          [color=blue]
          > When i have a baseclass which i want to use in different solutions, then
          > i add the class to a solution. The IDE copies the file to the other
          > solution folder and i have 2 copies of the same class file.[/color]

          Yes, it will do that if you tell it to.

          [color=blue]
          > The idea of inheritance is reusable code, but when i have 2 identical
          > files on different locations do i have to edit them both when something
          > changes to my baseclass???[/color]

          That's not how I'd do it.

          [color=blue]
          > Should i use a dll? I know it's a possible solution but not the most nice
          > one.[/color]

          Well yes, you should fully design your base class before you put it to
          use in a bunch of other apps, but you don't have to.
          [color=blue]
          > Why hasn't MS thought about this?[/color]

          What makes you say that? Again, you should really check into what
          the tools can do for you, before you ask why they haven't provided
          what you need. What you apparently want is provided for, and its
          called linking. You can link any file to your current project simply
          by telling VS to link the file.
          [color=blue]
          > Has anyone an explanation?[/color]

          When you link a file to your project, it is left in its original directory
          and becomes a part of your project, just like the other files. Changes
          you make (and save) to the file are reflected back to the original file
          in its original directory.

          LFS

          Comment

          • Johnny van Cadsand

            #6
            Re: Inheritance / file locations

            Larry Serflaten wrote :
            [color=blue][color=green]
            >> When i have a baseclass which i want to use in different solutions,
            >> then i add the class to a solution. The IDE copies the file to the
            >> other solution folder and i have 2 copies of the same class file.[/color]
            >
            > Yes, it will do that if you tell it to.[/color]

            I just add an existing class from an other solution to my solution and
            the IDE copies it.
            I found that...
            in a classlibrary it copies the original file but when i add an existing
            class to a windows application project it is left in its original
            directory and indeed the changes are reflected back to the original
            file...

            But nevermind the above...

            I wonder why it default copies the file when you can link it as well. And
            only in a classlibrary.

            --
            =============== =============== =============== =============== ==

            Johnny van Cadsand news ( ) cadsand ! demon ! nl

            ..:: Up to the Sky and Back ::..

            Comment

            • Larry Serflaten

              #7
              Re: Inheritance / file locations


              "Johnny van Cadsand" <news@nospam.ca dsand.demon.nl> wrote
              [color=blue]
              > I wonder why it default copies the file when you can link it as well. And
              > only in a classlibrary.[/color]

              I certainly don't know for sure, I wasn't making the decisions, but I
              would suppose that it was determined that over the long haul, in
              most cases, copying the file instead of linking, would be the choice
              most often selected.

              You can link the file you want by selecting to add an existing item,
              and instead of just clicking on the Open button, click on the down
              arrow beside the word Open, and select Link File....

              LFS

              Comment

              Working...