Callbacks are all the same and are not interfaces (Android)
Closed this issue · 3 comments
Hello
Is there any particular reason why you created one common class named Callback
and all the pubnub actions accept this class as callback mechanism?
Because well-known best practice regarding Java is to create interfaces for that manner. This interfaces should define only methods that this callback needs. For example publish needs only successCallback
and errorCallback
so interface should define only these two methods because publish method doesn't need reconnectCallback
and all other stuff.
So for your case you can do do one common interface (e.g. named Callback
) that defines successCallback
and errorCallback
methods. Because all five methods (publish
, subscribe
, presence
, detailedHistory
and hereNow
) uses at least these two methods. For example subscribe needs all five (connectCallback
, disconnectCallback
, reconnectCallback
, successCallback
and errorCallback
) so you create interface for subscribe that extends common interface (e.g. named SubscribeCallback extends Callback
) than you define just three missing methods and that is it.
If that is any particular reason why you do this like that, let me know. I really want to know and to extend my knowledge.
Best
zmeda
Hi @zmeda! Good question... let me research with engineering, and get back to you shortly on what we find.
This sounds very clean!
@zmeda we are getting through our backlog right now, I think within a week or so we'll be revisiting this and getting back to you on it. hold tight, and thanks for your patience!