views:

77

answers:

1

I have an existing program we've developed as a large set of Eclipse plugins. One of the plug-ins is responsible for reading internal information and generating an output file that is fed to another system.

This output file's format is fully specified in a controlled document.

Now I need to extend this application to output a newer version of this format, but I don't want to lose the ability to output the old version. The two are similar enough that I could get away with a couple of 'if' statements, but that's not the OO way.

It seems like I should have a new plug-in that provides the new file format, and then somehow uses an extension point to find a plug-in that implements the requested format. One approach would be to make the extension point's name encode the format ID.

Then I have to configure in some fashion which format this particular program wants to use.

Are there any best practices people can suggest? Eclipse is such a large platform that there are dozens of ways to do things and not always a clear winner.

+1  A: 

Here's what I ended up with.

We already had somethng called ImplProvider, which provided an easy abstraction for extension points. Give it an extension point to search for, and it would find somebody who extends that point and instantiate the described class. Pretty typical Eclipse.

I extended that by allow the user to pass in a Map of attributes. The extension point definition includes a new element called "identifier", and when it searches for a matching extension point the "identifer" section must contain all of the attributes you asked for.

All "exporters" are implemented in this method, and define two attributes: "icd" and "type". "icd" stands for Interface Control Document... you could imagine it's values to be something like "HTML5", "RFCxxxx", or in my case a company proprietary number assigned to the document that describes the file format. The "type" field is there because sometimes an ICD might define multiple file formats, so you need some way to pick one.

So now when I want to output a file, I can look up the preferred ICD, or have the product specify the ICD to use. The class that actually does the output is looked up through this mechanism.

Chris Arguin