Interfaces problem

P

pnp

Hi all,
I've created an app that loads some dlls dynamically from the
filesystem. All the dlls implement a certain interface so that they can
be easily manipulated from the main app. The dlls work as plugins for
the main app.
What I want to do is give some extra functionality to the dlls so that
each dll can have some extra functions inside it, that the other dlls
are not required to have (so I cannot add more functions to the main
interface that all the dlls implement). I would like all the changes to
be made to the plugin dlls and not the main app (so when a new plugin is
created I wouldn't like to change the main app as well).

How can I achieve this?

-pnp
 
J

John Sun

pnp said:
Hi all,
I've created an app that loads some dlls dynamically from the
filesystem. All the dlls implement a certain interface so that they can
be easily manipulated from the main app. The dlls work as plugins for
the main app.
What I want to do is give some extra functionality to the dlls so
that each dll can have some extra functions inside it, that the other
dlls are not required to have (so I cannot add more functions to the
main interface that all the dlls implement). I would like all the
changes to be made to the plugin dlls and not the main app (so when a
new plugin is created I wouldn't like to change the main app as well).

How can I achieve this?

-pnp
You can create the classes inheriting from the classes which implement
the common interfaces. I just don't see why there is any problem there.

Jianwei
 
P

pnp

When I load the dll, I use it's functionality by unwraping it and
casting it to the main interface. If I create a class that inherits from
a class that implements the interface how would I use it's functions?
 
B

Bruce Wood

I see two possible solutions, depending upon how the extra functions in
the various DLLs are related, and whether they logically fall into
groups that must either be completely implemented or not implemented at
all.

If you are going to have groups of extra functions, you could create
other interfaces that a given class may implement or not. Then, in the
main class, you could say

IOptionalInterface1 oi1 = loadedClass as IOptionalInterface1;
if (oi1 != null)
{
... call methods in optional interface ...
}

On the other hand, if your optional methods / properties are not
related in this way, then you may have to resort to using Reflection
and testing for particular method names. You can then invoke the
methods using Reflection as well.
 

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