Results 1 to 14 of 14

Thread: Impliments

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Impliments

    I don't really understand impliments so I was wondering if someone could explain it a little. I don't really understand it in VB6 or .NET

    I program in VB6 right now but I am reading some books on .NET to get up to speed with it. I have never had the need for impliments in my code so I never bothered to really figure it out.

    From what I can tell it is sort of like inheritence but it is to inherit an interface? When you impliment at interface, you aren't getting any code with it? just a list of subs/functions that your class must use in order to comply with the interface???

    what am I missing??

    I guess I just don't really see the point of them although I am sure they exist with good reason

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    You got it. The point is for something like plugins when you want to make sure the 3rd party developers implement the functions YOUR app expects to see and will try to call in the plug-ins.

    You are then able to check if the plugin is implementing the correct interface before you load it so you dont have something crash trying to call functions in a plugin that are not there.


    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    ok so for example, why do you need to impliment the IDisposable interface to call the dispose method? couldn't you simply just make a dispost method and write the code for it without Implimenting the IDisposable interface? Or when you impliment that interface does that tell something else to the .NET framework that is needed?

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Because your app is like a plugin to the Garbage Collector and Just In Time Compiler. By implemetning IDisposable, the GC will know to clean up your app when it gets around to it. Just consider your .NET application as a plugin to the .NET framework and you can probably visualize it better.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    gotcha... ok so what use is it in VB6 then?

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Same thing. The only place I ever used Implements in VB6 was for COM+ MTS objects, in which case, the same scenario. The dll was a 'plugin' to MTS. And the implements was for the 3 or so functions it expected in your dll.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    gotcha.. seems to have a lot more use when it comes to .net... but then again i guess that is because it is a form of inheritence and as we know VB6 was lacking in that area

  8. #8
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    Investigate Polymorphism. There are plenty of good articles in MSDN on the subject. To understand the implements key word, you must have an understanding of polymorphism.

    I have found countless uses for polymorphism in my apps, and they work brilliantly. When you figure out how to use the concept correctly, you will feel like you're on a whole other level of programming.

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    polymorphism!

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Here is a code example to show you sort of how polymorphing works.
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         'make two instances of different kinds of objects
    4.         Dim objOfOneType As New Car("Dodge Stratus", 2002, Color.Blue)
    5.         Dim objOfAnotherType As New Person("Ed", 27)
    6.  
    7.         'now cast the specific type to the interface it implements
    8.         Dim generic As IGenericName = objOfOneType
    9.         'run interface members regardless of what they are actually called in the class itself
    10.         generic.Display() 'will show "Dodge Stratus" in msgbox
    11.  
    12.         'now for the other object
    13.         generic = objOfAnotherType
    14.         generic.Display() 'will show "Ed Marquez" in msgbox
    15.  
    16.         'See how both can be used as IGenericName even though they are actually of other types.
    17.         'This could also be useful with method as you can have IGenericName as the parameter type
    18.         'then anything that implements it regardless of actual type can be passed in.
    19.  
    20.         'This is the basics of polymorphic behavior, since the types can polymorph or change into other types.
    21.  
    22.     End Sub
    23.  
    24. 'example interface provides a required structure
    25. Public Interface IGenericName
    26.  
    27.     Property Name() As String
    28.     Sub Display()
    29.  
    30. End Interface
    31.  
    32. Public Class Car
    33.     Implements IGenericName
    34.  
    35.     Private _Make As String = String.Empty
    36.     Private _Year As Integer = 2000
    37.     Private _Color As Color = Color.Blue
    38.  
    39.     Public Property Make() As String Implements IGenericName.Name
    40.         Get
    41.             Return _Make
    42.         End Get
    43.         Set(ByVal Value As String)
    44.             _Make = Value
    45.         End Set
    46.     End Property
    47.  
    48.     Public Property Year() As Integer
    49.         Get
    50.             Return _Year
    51.         End Get
    52.         Set(ByVal Value As Integer)
    53.             _Year = Value
    54.         End Set
    55.     End Property
    56.  
    57.     Public Property Color() As Color
    58.         Get
    59.             Return _Color
    60.         End Get
    61.         Set(ByVal Value As Color)
    62.             _Color = Value
    63.         End Set
    64.     End Property
    65.  
    66.     Public Sub ShowMake() Implements IGenericName.Display
    67.         MsgBox(Me.Make, , "Car")
    68.     End Sub
    69.  
    70.     Public Sub New(ByVal make As String, ByVal year As Integer, ByVal color As Color)
    71.         Me.Make = make
    72.         Me.Year = year
    73.         Me.Color = color
    74.     End Sub
    75.  
    76. End Class
    77. Public Class Person
    78.     Implements IGenericName
    79.  
    80.     Private _Name As String = String.Empty
    81.     Private _Age As Integer = 25
    82.  
    83.     Public Property Name() As String Implements IGenericName.Name
    84.         Get
    85.             Return _Name
    86.         End Get
    87.         Set(ByVal Value As String)
    88.             _Name = Value
    89.         End Set
    90.     End Property
    91.  
    92.     Public Property Age() As Integer
    93.         Get
    94.             Return _Age
    95.         End Get
    96.         Set(ByVal Value As Integer)
    97.             _Age = Value
    98.         End Set
    99.     End Property
    100.  
    101.     Public Sub SayName() Implements IGenericName.Display
    102.         MsgBox(Me.Name, , "Person")
    103.     End Sub
    104.  
    105.     Public Sub New(ByVal name As String, ByVal age As Integer)
    106.         Me.Name = name
    107.         Me.Age = age
    108.     End Sub
    109.  
    110. End Class

  11. #11
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    As a side not it's Implements
    \m/\m/

  12. #12
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    A 'side not'?

    lol

  13. #13

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    lol well at least VB is good at correcting my bad spelling

  14. #14
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Originally posted by nemaroller
    A 'side not'?

    lol
    Oh the irony.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width