Skip to content

Instantly share code, notes, and snippets.

@matzew
Created October 24, 2012 12:09
Show Gist options
  • Save matzew/3945727 to your computer and use it in GitHub Desktop.
Save matzew/3945727 to your computer and use it in GitHub Desktop.
Private versus internal API

Not exposing implementation details

Looking at this pull request and the related discussion:

  • the Pipe interface is the only access that endusers should have to a pipe.
  • the RestAdapter is a HTTP RESTful implementation of the Pipe.
  • Endusers should not be able do do new RestAdapter(...);

Looking at the discussion of the above PR, it's clear that there exposing internal APIs and/or implementation details has PROs and CONS...

  • It's BAD because it leaks API and once endusers start using it... you are lost (and need to support it ...)
  • Exposing the internal API makes the library more flexible on the other hand

Flexibility

If someone wants to implement a bit different marshalling / unmarshalling they would have to use a slightly different (new) implementation, since the class is not exposed... So they would copy/paste the entire class and simply change the details they want to change... Of course that's a valid complain about bad design that they can't simply extend the library.

Extensibility

It would be good if there is an SPI on the library where customers/endusers could register their "RESTFull Pipe implementation". It would be also cool if we could offer some abstract API (AbstractPipeAdapterClient) which is flexible enough that endusers can extend from that without the need to mess around with our internal API (e.g. RestAdapter).

We we introduce these things,we can keep our implementation details for us... but still we are giving the enduser an api to EXTEND from an abstract BASE, and they can register that for certain "transports"...

@mstruk
Copy link

mstruk commented Oct 24, 2012

Yes, it would be an option, with a few caveats.

  • It's supported since Level 9 API. Our TODO demo app targets Level 7 and above.
  • Last time I used it it was a second-rate citizen in that it required extra tricks to package META-INF/*** to enter an .apk archive. I addressed it by unpacking, modifying, and repacking the .apk using additional custom scripts. When building through IDE without maven it can happen that the step is skipped, producing a 'corrupted' .apk - one without META-INF/services ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment