I generally dislike the usage of singletons or static class, since I can refactor them to something different most of the time.
However, I am currently designing my access point to a HTTP API on an Android app, and I was thinking that I have the following environment:
- I need to send HTTP requests in the majority of my code modules (Activities).
- The code for sending a request does not depend on the request being sent
- There will always only be one specific user on the app per session (unlike the server-side that has to handle different users etc)
Therefore, I was thinking that this could be a situation where it is justifiable to use a Singleton, or even a static class, to place HTTP requests - In the rest of my code, I would then simply have to use something like:
MyHttpAccess.attemptLogin(name, pass, callback)
in order to complete the request. I'm even leaning towards using a static class, as I do not have any variable data that I can think of needing to store.
Does this seem like good or bad design, and what should I potentially change?
Aucun commentaire:
Enregistrer un commentaire