1

My application will output a graph, for which the layout is to be defined by the user. The custom layout class should implement an interface defined by me. How should I do this? Have a special folder where I look for layout classes? Have the user pass the class name as argument to the app?

Any help would be greatly appreciated.

1
  • What sort of app? web app, JWS, standalone Swing app disgused as a native desktop application? Commented Feb 3, 2011 at 18:34

2 Answers 2

3

Multiple approaches used at the same time usually give the best results here. Different users may choose different ways to configure your application. For example:

  • A default directory where users can put plugins. Or even a list of directories, which could include some subdirectory of the application folder, some system-wide directory in the platform-dependent "application data" place, some user-local directory.
  • A config file with some options to control plugins search and selection.
  • A Java system property which specifies a list of directories to search for plugins, like java -Dorg.something.appname.plugindirs=plugindir1;plugindir2.
  • A special command-line option or Java system property to select a particular plugin, possibly providing an absolute path or just a name to look up in the directories specified by the methods above.

I think that the more ways your application provide, the better. Of course, it should have some sort of default setup so users won't have to bother with all that stuff if they don't want to. Also, the order of using those options should be sensible: for example, it makes perfect sense for the user plugins to override the system ones, not the other way around.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you suggest some examples of programs that work this way, and do it well? Apart from maybe Emacs, I'm having trouble thinking of any that don't just pick one of those approaches and do it right.
@David, since you have mentioned Emacs, mentioning Vim too is mandatory. Mozilla Firefox has at least two places where it looks for plugins, the system-wide directory and the user-local directory, but it also provides the "-profile" option to specify path to an alternate user profile. qmake from the Qt toolkit looks for additional "features" in a lot of places specified in different ways and it makes sense too.
0

The model chosen by toolkits years over, AWT, Swing, etc. is to be passed the layout as an argument to your API. Assuming you're being invoked from the commandline:

java -jar yourapp.jar;theirintf.jar yourapp org.example.theirintf  

Don't try and be overly magical with special folders and conventions. Just take it as an argument. Please have a default value if the user choose not to create one of their own - your app should be usable on it's own.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.