|
-
Sep 11th, 2000, 04:22 PM
#1
Thread Starter
Addicted Member
-
Sep 11th, 2000, 05:03 PM
#2
Hyperactive Member
Implements refers to giving multiple classes the same interface. I'm not very good at explaining it so I'll give you an example.
Code:
'' clsFruit.cls
'' base class is clsFruit
'' it has 1 member function as follows
Public Function WhatAmI() As String
WhatAmI = "All Fruits"
End Function
'' End of class clsFruit
'' clsApple.cls
'' now we have a second class (clsApple) which implements clsFruit
'' implement class clsFruit
'' it's like saying clsApple is a clsFruit
Implements clsFruit
'' redefine the function "WhatAmI"
Private Function clsFruit_WhatAmI() As String
clsFruit_WhatAmI = "Apple"
End Function
'' End of class clsApple
'' now we can do the following
Dim fruit as clsFruit
Set fruit = new clsFruit
'' this will return "All Fruits"
Debug.Print fruit.WhatAmI()
'' we can also do this:
Set fruit = new clsApple
'' this will return "Apple"
Debug.Print fruit.WhatAmI()
get it?
-
Sep 11th, 2000, 06:24 PM
#3
Hyperactive Member
I get it
I thought that was well done MrShickadance.
I have not used it in my own code as yet (although I have used other class libraries which use Implements keyword).
The general purpose of such a keyword is not very well supported in VB today. From what I understand VB7 will be providing much better Object Oriented Programming tools with three new keywords for that purpose.
As MyShickadance said, Implements allows you to standardise related classes by providing you with the opportunity to specify a set of functions or subs that all related classes MUST implement (this is where you use the Implements keyword).
So in the example, MrShickadance was telling VB that clsApple Implements the clsFruit interface (interface just means set of functions and subs). If MrShickadance forgot to create one of the subs that clsFruit had in his clsApple class, then VB would have complained.
So how it helps you is that you can sleep soundly at night knowing that if you decided to change the name of a sub in clsFruit one day or if you added or removed one, VB would make you update all the other classes that Implement clsFruit before you can execute the code.
I doubt my explanation is enough to get you interested in OO design, but then, VB isn't yet the ideal mechanism to learn OO anyhow 
Cheers
Paul Lewis
-
Sep 11th, 2000, 08:05 PM
#4
Fanatic Member
I haven't used it much but I've been reading about it a bit lately, but I thought that the functions and subs had to be left unimplemented in the base class! and then implemented in the new classes.
can you write the line
WhatAmI = "All Fruits"
or not?
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|