Eclipse Design Patterns – Singleton in Platform

Actually this is the simplest pattern in this Eclipse Design Patterns series. The basic idea of a Singleton pattern is there is always only one instance for a target object.

The following simply gives several examples from commonly used Eclipse API. Note that not all methods are from org.eclipse.core.runtime.Platform.

Platform.getAdapterManager(); //only one AdapterManager
PlatformUI.getWorkBench(); // only one workbench
//get workbench window
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
ResourcesPlugin.getWorkspace(); // only one Workspace

For more examples, you can browse the source code of eclipse.

Leave a Comment