Interface vs Struct

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?U29BekFwcERldmVy?=

    Interface vs Struct

    I am new to object oriented design. I am using VS 2005. I was going to
    create three classes then have those classes inherited by one class but c#
    does not support multiple inheritance. My three base classes would have
    properties only and no methods. What would be best to use in this case an
    interface or struct or something else?

    When adding items to the project I did not see a template for struct or for
    an interface, but there is a template for class (.cs).

    Originally I had planned to have three base classes:
    Owner class, Property Class and Value Class

    And a PropertyHistory class that would inherit all the base classes and
    PropertyHistory could be added to a collection so I could iterate through it
    and sort it.

    I wanted the base classes to be reused separately in other areas of the
    application.

    What is the best way to do this?

    --
    Happy In SoAz
  • =?UTF-8?B?QXJuZSBWYWpow7hq?=

    #2
    Re: Interface vs Struct

    SoAzAppDever wrote:
    I am new to object oriented design. I am using VS 2005. I was going to
    create three classes then have those classes inherited by one class but c#
    does not support multiple inheritance. My three base classes would have
    properties only and no methods. What would be best to use in this case an
    interface or struct or something else?
    Neither interface or struct solves that problem.

    I think you need to make the one class have a reference to the
    3 "base" classes instead of inheriting.

    Arne

    Comment

    • =?Utf-8?B?U29BekFwcERldmVy?=

      #3
      Re: Interface vs Struct

      So In the PropertyHistory class I could pass in the three base classes like so

      class PropertyHistory (Owner oObj, Property oProp, Value oVal)
      {
      do stuff
      }

      ?

      --
      Happy In SoAz


      "Arne Vajhøj" wrote:
      SoAzAppDever wrote:
      I am new to object oriented design. I am using VS 2005. I was going to
      create three classes then have those classes inherited by one class but c#
      does not support multiple inheritance. My three base classes would have
      properties only and no methods. What would be best to use in this case an
      interface or struct or something else?
      >
      Neither interface or struct solves that problem.
      >
      I think you need to make the one class have a reference to the
      3 "base" classes instead of inheriting.
      >
      Arne
      >

      Comment

      • Arved Sandstrom

        #4
        Re: Interface vs Struct

        "SoAzAppDev er" <SoAzAppDever@d iscussions.micr osoft.comwrote in message
        news:3B6FF8B1-C15C-4BDB-942A-AE28340FCFF5@mi crosoft.com...
        So In the PropertyHistory class I could pass in the three base classes
        like so
        >
        class PropertyHistory (Owner oObj, Property oProp, Value oVal)
        {
        do stuff
        }
        >
        ?
        >
        "Arne Vajhøj" wrote:
        >
        >SoAzAppDever wrote:
        I am new to object oriented design. I am using VS 2005. I was going
        to
        create three classes then have those classes inherited by one class but
        c#
        does not support multiple inheritance. My three base classes would
        have
        properties only and no methods. What would be best to use in this case
        an
        interface or struct or something else?
        >>
        >Neither interface or struct solves that problem.
        >>
        >I think you need to make the one class have a reference to the
        >3 "base" classes instead of inheriting.
        >>
        >Arne
        Arne means that since PropertyHistory is not a Property, nor is it a Owner,
        nor is it a Value, it won't inherit from any of them. An instance of
        PropertyHistory will have references to an instance of Property, an instance
        of Owner, and an instance of Value.

        AHS


        Comment

        • =?Utf-8?B?U29BekFwcERldmVy?=

          #5
          Re: Interface vs Struct

          I am not sure I understand. Can you show me in code? What is have done is
          the following:

          public class ParcelHistory
          {
          //members
          private Owner _owner;
          private Property _property;
          private Value _value;


          //contructor
          public PropertyHistory (Owner owner, Property property, Value value)
          {
          _owner = owner;
          _property = property;
          _value = value;
          }

          //properties
          public Owner HistoryOwner
          {
          get { return _owner; }
          }

          public Property HistoryProperty
          {
          get { return _property; }
          }

          public Value HistoryValue
          {
          get { return _value; }
          }

          }


          --
          Happy In SoAz


          "Arved Sandstrom" wrote:
          "SoAzAppDev er" <SoAzAppDever@d iscussions.micr osoft.comwrote in message
          news:3B6FF8B1-C15C-4BDB-942A-AE28340FCFF5@mi crosoft.com...
          So In the PropertyHistory class I could pass in the three base classes
          like so

          class PropertyHistory (Owner oObj, Property oProp, Value oVal)
          {
          do stuff
          }

          ?

          "Arne Vajhøj" wrote:
          SoAzAppDever wrote:
          I am new to object oriented design. I am using VS 2005. I was going
          to
          create three classes then have those classes inherited by one class but
          c#
          does not support multiple inheritance. My three base classes would
          have
          properties only and no methods. What would be best to use in this case
          an
          interface or struct or something else?
          >
          Neither interface or struct solves that problem.
          >
          I think you need to make the one class have a reference to the
          3 "base" classes instead of inheriting.
          >
          Arne
          >
          Arne means that since PropertyHistory is not a Property, nor is it a Owner,
          nor is it a Value, it won't inherit from any of them. An instance of
          PropertyHistory will have references to an instance of Property, an instance
          of Owner, and an instance of Value.
          >
          AHS
          >
          >
          >

          Comment

          • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

            #6
            Re: Interface vs Struct

            Arved Sandstrom wrote:
            "SoAzAppDev er" <SoAzAppDever@d iscussions.micr osoft.comwrote in message
            news:3B6FF8B1-C15C-4BDB-942A-AE28340FCFF5@mi crosoft.com...
            >"Arne Vajhøj" wrote:
            >>SoAzAppDeve r wrote:
            >>>I am new to object oriented design. I am using VS 2005. I was going
            >>>to
            >>>create three classes then have those classes inherited by one class but
            >>>c#
            >>>does not support multiple inheritance. My three base classes would
            >>>have
            >>>properties only and no methods. What would be best to use in this case
            >>>an
            >>>interface or struct or something else?
            >>Neither interface or struct solves that problem.
            >>>
            >>I think you need to make the one class have a reference to the
            >>3 "base" classes instead of inheriting.
            >So In the PropertyHistory class I could pass in the three base classes
            >like so
            >>
            >class PropertyHistory (Owner oObj, Property oProp, Value oVal)
            >{
            >do stuff
            >}
            >>
            >?
            >
            Arne means that since PropertyHistory is not a Property, nor is it a Owner,
            nor is it a Value, it won't inherit from any of them. An instance of
            PropertyHistory will have references to an instance of Property, an instance
            of Owner, and an instance of Value.
            Yup.

            3 x "has a" instead of the invalid 3 x "is a".

            Arne

            Comment

            • Jeff Louie

              #7
              Re: Interface vs Struct

              As Arne suggest..

              Inheritance represents an IS_A relationship from a generalization to a
              specialization. Containment represents a HAS_A relationship between the
              whole and a part. So a car IS_A motorized vehicle, but HAS_A radio. The
              two
              relationships can be expressed in code (text view) thusly:

              class Radio
              {
              ...
              }
              class Vehicle
              {
              ...
              }
              class Car : Vehicle
              {
              Radio r= new Radio();
              }

              Regards,
              Jeff

              *** Sent via Developersdex http://www.developersdex.com ***

              Comment

              • =?Utf-8?B?U29BekFwcERldmVy?=

                #8
                Re: Interface vs Struct

                Thank you that is very helpful!
                --
                Happy In SoAz


                "Jeff Louie" wrote:
                As Arne suggest..
                >
                Inheritance represents an IS_A relationship from a generalization to a
                specialization. Containment represents a HAS_A relationship between the
                whole and a part. So a car IS_A motorized vehicle, but HAS_A radio. The
                two
                relationships can be expressed in code (text view) thusly:
                >
                class Radio
                {
                ...
                }
                class Vehicle
                {
                ...
                }
                class Car : Vehicle
                {
                Radio r= new Radio();
                }
                >
                Regards,
                Jeff
                >
                *** Sent via Developersdex http://www.developersdex.com ***
                >

                Comment

                Working...