Internal interfaces separated from external API as in Eclipse

Aus SDQ-Wiki

See also an Eclipse Corner Article (that is apparently "deprecated" without any given reason).

To separate API methods that should be callable by external code from internal methods you can use a pattern that is used at many places in the Eclipse framework:

<uml> !include kit-blue.iuml !include sans-serif.iuml interface YourInterface {

externalAPIMethod()

} interface InternalYourInterface {

internalMethod()

} YourInterface <|-- InternalYourInterface class YourInterfaceImpl {

externalAPIMethod()
internalMethod()

} InternalYourInterface <|-- YourInterfaceImpl </uml>

The important part of this simple pattern is:

  • if you provide objects of your implementation class YourInterfaceImpl to external code, then type it only using the API interface YourInterface
  • only type objects of your implementation class YourInterfaceImpl with the internal interface InternalYourInterface if you want the code to use the internal methods

Note: It is easy for external code to simply cast an object typed YourInterface to InternalYourInterface, but the necessity to perform such a explicit cast is exactly what this pattern gives you. Not more.