Robert.. You can use interfaces or an abstract base class to abstract
out the
functionality of the plug ins. You then program to the abstraction. In
the case
of an interface, you program to the public view, the interface. The
interface
defines a contract between the user of your plug in class and any
concrete
implementation of the class. The caller programs to the type. The caller
does
not need to know the class of the object only that the object implements
the
type. The class, however, is discoverable at runtime.
A common example of using plug ins is a menu. You can place your plugins
in a plugins folder and dynamically load the types at runtime and then
dynamically populate the menu at runtime. When the user selects a
concrete
implementation from the menu, you can instantiate the concrete class
using
a type based factory method.
public IDrawableShape GetInstance(str ing key)
{
...
else
{
Type t= (Type)hash[key];
// dynamically load this class
return (IDrawableShape )Activator.Crea teInstance(t);
//else return null;
}
}
The problem with this approach is that concrete types known at _compile
time_ are also late bound in this approach. So a better approach is to
use
inheritance to create a hierarchy of class factories. Classes know at
compile
time are created using early binding and classes discovered at runtime
are
created using late binding.
Regards,
Jeff
*** Sent via Developersdex http://www.developersdex.com ***
out the
functionality of the plug ins. You then program to the abstraction. In
the case
of an interface, you program to the public view, the interface. The
interface
defines a contract between the user of your plug in class and any
concrete
implementation of the class. The caller programs to the type. The caller
does
not need to know the class of the object only that the object implements
the
type. The class, however, is discoverable at runtime.
A common example of using plug ins is a menu. You can place your plugins
in a plugins folder and dynamically load the types at runtime and then
dynamically populate the menu at runtime. When the user selects a
concrete
implementation from the menu, you can instantiate the concrete class
using
a type based factory method.
public IDrawableShape GetInstance(str ing key)
{
...
else
{
Type t= (Type)hash[key];
// dynamically load this class
return (IDrawableShape )Activator.Crea teInstance(t);
//else return null;
}
}
The problem with this approach is that concrete types known at _compile
time_ are also late bound in this approach. So a better approach is to
use
inheritance to create a hierarchy of class factories. Classes know at
compile
time are created using early binding and classes discovered at runtime
are
created using late binding.
Regards,
Jeff
*** Sent via Developersdex http://www.developersdex.com ***