Sign in to follow this  
haust

Pluggable factories and dll ??

Recommended Posts

hi, i've just read Timothy R. Culp's "Industrial Strength Pluggable Factories" article (http://www.adtmag.com/joop/crarticle.asp?ID=1520) and somewhere he talks about adding new object types by using plugins "These plug-in libraries are loaded at runtime (using dlopen for UNIX or LoadLibrary for Windows) to extend the shape hierarchy dynamically without modifying the Shape class". My question is how is this possible ?? As far as I understand it, the system is based on a template with a registry map where each new derived class is automatically added to this registry. The main requirement for this to work is that the registry map must be unique (use of static). Now if I want to create a new class in a separate dll, I will have another static registry which breaks the pattern. If someone can explain me what I didn't understood it would be cool :). haust.

Share this post


Link to post
Share on other sites
He doesn't really explain how to do it, but here's how i would handle the case:

If using a DLL you obviously can't use a static map as you found it will be a second instance inside the dll. Instead you export a RegisterPlugin function that accepts a generic factory container. The function will register the dlls factories in the passed container.

I'm using this for example for a image format loader manager which i pass to my abstract renderer inside a dll. So the main app decides which formats are available by registering them and the renderers just look inside the list (simplified).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this