A system design is decoupled into two layers say layer A and layer B. The interaction between layer A and layer B occurs through an interface that is exposed by layer B in form of an API. This interaction has an asynchronous design pattern. Layer A registers a callback function with the layer B API. Now can one technically refer to the callback function as exposed by layer A and refer to it as API of layer A?


1 Answer 1


Normally, no. The callback is part of the API exposed by layer B.

The API of Layer B defines the form (prototype) of the callback, the API of Layer B defines the functions to register and unregister the callback, and Layer B defines the conditions under which the callback will be invoked. Furthermore, since the callback gets registered, it will work even if it is not publicly exposed by Layer A. (The callback can be a private method of the object that implements Layer A.) Therefore, it is totally, completely, unquestionably, part of Layer B's API.

Now, if Layer A decides to also publicly expose the callback, then it also becomes part of Layer A's API, but that's twisted, and probably useless. The chances of some third Layer X finding it useful to invoke the callback of A as part of the public API of A are very slim. As a matter of fact, even on such an unlikely occasion, I would still avoid having Layer X invoke the callback, because it would cause confusion. I would have A expose an entirely separate method for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.