Callback a better way

Hi everyone, What is that? well a simple callback is a structure for ask a service/module/api to get an answer/response.

  1. Hey: Why do i need change me methods to callback?
    • Simple response, thats it, a simple response that could be able to change in the future, that could help you too make unit tests.
  2. but i made some codes and never need it.
    • Maybe you don’t need it, cuz just use synchronize thread, but hardly never that happen in your software life. if you need read imforrmation from an Internet Of Things(IOT) via bluetooth, WiFi, or Radio Frequence identification (RFID), you’ll have to link devices via multi-threads so you need understand how asynchronize threads worked with callbacks. In this days all program languages know that.

In this example you could code a simple callback:

  • ServiceCallback: it’s a callback interface, witch help pass different response for each task
  • Service: it’s a kind of Api/Service/or whatever device arquitecture, that ‘ll implement the real connection between a client and you.

You just need call the method that you want, for each request objects, you’ll have a different response. For example avoid you’ll be good at thinking about what happer if something have a problems, you could skip and continue work with just successful objects.

Otherwise callbacks allow you build unit test perfetly, without devices or services that still not working or doesn’t exist.