(Jul 26, 2013 04:29 AM)stefsot Wrote: When using interface you cannot add or remove anything in your class.
It could be used better like this
Code
Public Class IPlugin
Public Overridable Sub OnLoad()
End Sub
Public Overridable Sub Refresh()
End Sub
Enc Class
Code
Public Class Plugin_test
Inherits IPlugin
Overrides Sub OnLoad()
Console.Write("hi!!")
End Sub
Enc Class
True, but this tutorial was more about using interfaces. Interfaces should contain only just a few declarations specific for the interface.
What I have used before is an interface called IPlugin, that has a definition like this:
PHP Code
<?php
Public Interface IPlugin
Sub Execute(...)
End Interface
Using this in a class would require me to implement the Execute sub.
PHP Code
<?php
Public Class MyPlugin
Implements IPlugin
Sub Execute(...)
End Sub
End Class
If I wanted to extend the plugin with something like file handling operations, I need more methods indeed. I created another interface, called IFileHandler to solve this:
PHP Code
<?php
Public Interface IFileHandler
Sub OpenFile(...)
Sub SaveFile(...)
End Interface
Implementing these methods in the MyPlugin class will give me this:
PHP Code
<?php
Public Class MyPlugin
Implements IPlugin, IFileHandler
Sub Execute(...)
End Sub
Sub OpenFile(...)
End Sub
Sub SaveFile(...)
End Sub
End Class
Now my plugin supports more methods to be called from the main application. In your case you would add an interface called IRefreshable or something among those lines.
The point of this is, that interfaces provides us a very good base for extending classes' functionality. I think interfaces are very well suited for these kind operations, as they give you the opportunity to "personalize" a type. This can be achieved partly with MustInherit classes, and I do believe your example is good and I sometimes use abstraction too instead of interfaces, but you should feel the power of interfaces because of their flexibility.