How to get components transparency from implementation or abstraction?

Hello,

I have the IDEA component - TheComponent, it is interface:


I have 'hidden' (package view) implementation:


plugin.xml:

    my.components.TheComponent
    my.components.impl.TheComponentImpl

]]>


Now, to get this component fully transparent (I Know Only Interface):


+
BTW. Very strange, but Application.getComponent does not use generics signature, i need cast it anyway...
+

This is not very good - in any place, there i need to use component i must get Application and get Component from it.

Let look on IDEA core, any system components, as FileTypeManager - is not interface, but abstract class with getInstance method, there incapsulates Application.getComponent.

At end, i found some trick but i think, that it is not good also: you can pass interfaces of components into referenced component's constructor:


It look like memmory leaks :) ... but more clearly and this is picocontainer feature.


The question is: Is anybody have some fine solution, how keep interfaces instead of abstract classes and get this component is very simplest that caling every time Application.getComponent?

I not mean that Application.getComponent is poor, but it is not realy clear. Becouse its hidden 'ServiceLocator' problem and it can force initialization problems also.

I can't sure that is realy right. Storing links to components in all referenced components or use Application.getComponent in every place where i need for it?

Thanks!

Please sign in to leave a comment.