hgoebl / DavidWebb

Lightweight Java HTTP-Client for calling JSON REST-Services (especially for Android)
https://hgoebl.github.io/DavidWebb/
MIT License
127 stars 41 forks source link

Change Webb and WebbUtils to provide a protected constructor. #6

Closed pre closed 10 years ago

pre commented 10 years ago

Private constructor does not allow these classes to be inherited.

There are valid cases for extending the behaviour, but having a private constructor does not allow it.

hgoebl commented 10 years ago

Hi @pre, glad you're contributing back - thank you!

I'd be interested in your use-case of extending both classes. WebbUtils has only static methods, so inheriting does not make a lot of sense IMO. Webb could be extended, but the handling is then a bit strange since there is a static factory for getting an instance.

I'm not saying that I'm not willing to merge your pull request, but there are chances to enhance the library maybe with an extension point, some kind of plugins or the like.

Can you tell me in which way you want to extend or enhance DavidWebb?

pre commented 10 years ago

In our quite massive Android app, we've established from the start a design principle where we never access third party modules directly. That is, we always use a proxy or a facade class. This allows us to maintain control over the API, which allows us to change the internal implementation without too much refactoring elsewhere in the codebase.

So instead of directly instantiating from Webb, we'd make a proxy eg. AGLightweightHttpClient which inherits from Webb. For simple cases a proxy is the easiest solution since it can delegate to the internal implementation without extra effort.

For more complex cases (eg. Android WebView) a facade class is necessary. For example, when we need to expose a little bit different API than which is provided by the internal implementation.

I have to confess, I didn't test out whether it is actually possible to use Webb with a proxy class or is a full-weight facade required. However, I think having constructors as protected wouldn't do any harm, since these constructors seem to be made private in favor of the singleton (not in favor of disallowing inheritance).