Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[TUTORIAL] Make your application support Plugins (FULL SOURCE)

@TheUnknownProgrammer
Thank you, very nice tuto, can you advice me some details?
I'm try to use PluginConnector lib directly from project as new class but alway get stuck at executing instance
Quote:Unable to cast object type "Plugin.StartOfPlugin" to type "Plugin_System.IPlugin"


here:
Quote:Dim pluginclass As IPlugin = CType(Activator.CreateInstance(pluginassembly.GetType(pluginassembly.GetName.Name & ".StartOfPlugin")), IPlugin)

😵
Nice tut that plugin looks nice as well.
[Image: YolfK0b.jpg]
Great tutorial, really helpful. Thanks a lot :)
(Jul 25, 2013 09:56 AM)Felix.Frogg Wrote:  @TheUnknownProgrammer
Thank you, very nice tuto, can you advice me some details?
I'm try to use PluginConnector lib directly from project as new class but alway get stuck at executing instance

here:
😵

Did you implement the interface in your class correctly? Can you show me the exact source of your plugin?
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."
Wow pretty good someone was grave-digging.
I was talking to my partner about that last night, I really need this!
Thanks :3
Sometimes, grave-digging is useful! I will bookmark this tutorial for later ;D
Nice, I was looking for this. Thanks.

BTW, NVM if it is grave-digged.
Thank you TUp is very good code example plugin nice share
(Jul 25, 2013 12:36 PM)Washi Wrote:  Did you implement the interface in your class correctly? Can you show me the exact source of your plugin?

PMed you my source. Thanks in advance
Best Regards, UL
🤝
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
(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.
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by ( ͡° ͜ʖ ͡°)Sep 9, 2019 11:22 PM 42 16,835 Sep 9, 2019 11:22 PM
Last Post: AnonFawkes
[Java] by TennoFeb 3, 2019 04:49 AM 4 307 Feb 3, 2019 04:49 AM
Last Post: Tenno
[Python] by SkidyMar 29, 2018 06:54 AM 3 167 Mar 29, 2018 06:54 AM
Last Post: .kr.