C# Class Library - Plugin vs Inheritance!

G

Guest

Hi there,

I had some doubts on creatings plugins.

As most example on the internet shows how to write plugins onto a plugin
host which is normally a windows form program.

1) Can i replace plugin host as class libraries instead of windows forms
program?

2) If it is just a class library, then why plugins? I can just write an
abstract class and let the 3rd party inherit from it, and write something on
my class? Then why plugins, so complicated?

Can anyone enlighten me? I can't think what so special with plugin on this
case?

The major reasons is that i am developing a new framework (or many chunks of
libraries integrated into 1 namespace). Once it is done, i do not plan to
code anymore. If in future, whoever want to add functionalities to the
framework, just write plugins and plug into this framework. But i am kind of
mix up, and why can't i just write a new library and inherit from the
abstract class.

Example:

Framework
-------------
Parent abstrac class - Dad.cs
Child class inherit from parent - Son1.cs, Son2.cs, Son3.cs
(compiled into DadFramework.dll)

In future:
I had a new class - Son4.cs

public class Son4 : Dad
{
// had all Dad implementation
}

So why plugins again?

Please help! Thanks.
 
R

Richard Blewett

What do you mean when you say "plug-ins". A plugabble framework is
essentially one where the framework doesn't require compile time knowledge
of the concrete (non-abstract) classes as compile time.

In other words, the framework is implemented in terms of abtractions (I'd
argue that interfaces are better than abstract base classes for this as you
don't dictate an implementors base class when they can only have one). Then
other people create implementations of your abstraction and either:

1) they run their code into your framework
2) they advertize their new component via, say, a config file, and your
framework creates an instance (via Activator.CreateInstance), casts it to
the known abstraction and calls it.

number 2) is how the extension framework of ASP.NET and Remoting work

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
 
J

Jon Skeet [C# MVP]

Chua Wen Ching said:
I had some doubts on creatings plugins.

As most example on the internet shows how to write plugins onto a plugin
host which is normally a windows form program.

1) Can i replace plugin host as class libraries instead of windows forms
program?

Yes, although obviously you'll need an executable *somewhere*.
2) If it is just a class library, then why plugins? I can just write an
abstract class and let the 3rd party inherit from it, and write something on
my class? Then why plugins, so complicated?

If you write an abstract class but don't have a plugin architecture,
how is the class library going to load your class?

The point of a plugin architecture is for an executable to load code
which was written later than it. If you're using a library for a new
executable, you don't need a dynamically loaded plugin architecture.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top