Interface question

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

    #1

    Interface question

    When defining a Interface, I don't seem to have the
    ability to define a constructor. Is this possible?

    If not, is there a way to keep people from using a default
    constuctor but instead force them to use one constructor?

    Thanx in advance
  • Tu-Thach

    #2
    Interface question

    Interfaces do not have constructors. They cannot be
    instantiated. Only implementing classes do.

    Tu-Thach
    [color=blue]
    >-----Original Message-----
    >When defining a Interface, I don't seem to have the
    >ability to define a constructor. Is this possible?
    >
    >If not, is there a way to keep people from using a[/color]
    default[color=blue]
    >constuctor but instead force them to use one constructor?
    >
    >Thanx in advance
    >.
    >[/color]

    Comment

    • Tian Min Huang

      #3
      RE: Interface question

      Hello Kevin,

      Thanks for your post. I agree with Tu-Thach that you need to implement a
      class instead of an Interface. Please note that the Interfaces only define
      a set of properties, methods, and events without providing implementation.
      They are implemented by classes and structs. Please refer to the following
      MSDN article for detailed information:

      Interfaces Overview
      http://msdn.microsoft.com/library/de...us/vbcn7/html/
      vaconinterfaces invisualbasic70 .asp

      Please feel free to let me know if you have any problems or concerns.

      Have a nice day!

      Regards,

      HuangTM
      Microsoft Online Partner Support
      MCSE/MCSD

      Get Secure! -- www.microsoft.com/security
      This posting is provided "as is" with no warranties and confers no rights.

      Comment

      • Kevin Phifer

        #4
        RE: Interface question

        Thanx for the responses,
        What I ended up finding was that I could create a base
        abstract class that implemented the constructor I wanted
        and when inheriting from it, it would accept only that one
        and wouldn't compile otherwise.
        However, I was attempting this because I wanted to force
        the way the class was loaded and new ones where created,
        so what I relized was I could create static methods on the
        base class. These static methods did nothing but throw an
        exception, there by forcing those who comsumed my base
        class to create new ones. This coupled with a private
        constructor effectively allowed me to force a object
        factory out of my base class. Does this make since?

        Anyway, if there is a better way to go about this I would
        love to know. Thanx again....

        [color=blue]
        >-----Original Message-----
        >Hello Kevin,
        >
        >Thanks for your post. I agree with Tu-Thach that you need[/color]
        to implement a[color=blue]
        >class instead of an Interface. Please note that the[/color]
        Interfaces only define[color=blue]
        >a set of properties, methods, and events without[/color]
        providing implementation.[color=blue]
        >They are implemented by classes and structs. Please refer[/color]
        to the following[color=blue]
        >MSDN article for detailed information:
        >
        >Interfaces Overview
        >http://msdn.microsoft.com/library/default.asp?[/color]
        url=/library/en-us/vbcn7/html/[color=blue]
        >vaconinterface sinvisualbasic7 0.asp
        >
        >Please feel free to let me know if you have any problems[/color]
        or concerns.[color=blue]
        >
        >Have a nice day!
        >
        >Regards,
        >
        >HuangTM
        >Microsoft Online Partner Support
        >MCSE/MCSD
        >
        >Get Secure! -- www.microsoft.com/security
        >This posting is provided "as is" with no warranties and[/color]
        confers no rights.[color=blue]
        >
        >.
        >[/color]

        Comment

        • Tian Min Huang

          #5
          RE: Interface question

          Hello Kevin,

          Thanks for your information. I believe creating a base abstract class is a
          good method to achieve your goal.

          Please feel free to let me know if any further is needed.

          Regards,

          HuangTM
          Microsoft Online Partner Support
          MCSE/MCSD

          Get Secure! -- www.microsoft.com/security
          This posting is provided "as is" with no warranties and confers no rights.

          Comment

          Working...