Adding new interfaces

New types of objects can be passed into a part's constructor by registering them with the the org.eclipse.core.component.types extension point. At this point, we should introduce the term component. A component is any sort of object that is created from an extension point by injecting arguments into its constructor. New-style parts are one sort of component, but there are other types of components as well.

The following example shows a sample types extension. This example specifies that the INameable interface should be available from a part's site.

<extension
      point="org.eclipse.core.component.types">
   <component
         initializer="org.eclipse.ui.part.SiteInitializer"
         interface="org.eclipse.ui.part.services.INameable"
         implementation="org.eclipse.ui.internal.part.services.NullNameableService"
         singleton="true"
   />
</extension>

The initializer attribute indicates where the interface will be used. For example, the string "org.eclipse.ui.part.SiteInitializer" means that the interface is used on a part's site. We could have also used "org.eclipse.ui.part.PartInitializer" if the interface was intended for parts themselves to implement.

The interface attribute is the name of the interface. This must exactly match the type that the component will receive in its constructor. If we create an extension that supplies Strings and a component asks for an Object, it will not use our extension even though it would have been a compatible type.

The implementation attribute identifies the default implementation of the interface. It either points to a component class that implements the interface or a ComponentFactory that can create them, for additional information, see the ComponentFactory section . This implementation is used to satisfy a dependency whenever a component requests this interface and it can't be found in its parent context. All interfaces must supply a default implementation. This means that a correctly written component will always work in a given scope, regardless of how many dependencies are supplied by its parent context. The implementation cannot override or extend the interface attribute by implementing additional interfaces. Other components can depend on this component through its registered interface, but cannot depend on the implementation class directly.

The singleton attribute indicates whether the default implementation is a singleton. If true, then a single instance will be created and shared between every other component that needs it. If false, then a new instance will be created for each container that needs it. For example, in the case of parts, singleton=:"false" would mean that one instance will be created for every part.