I am trying to design and implement a framework to communicate with server (it's an iOS framework written in Swift). The challenge I am facing is the architecture - there are two ways of communicating with the server and I have to implement both (different versions). I really want to achieve having a stateless client, with methods such as: Client.authenticate()
or Client.downloadFile()
. The problem is when having two implementations I would end up with methods in my Client class like this one:
public class func authenticate(state: state) {
if (state.type == 1) {
Client1.authenticate(state)
} else {
Client2.authenticate(state)
}
}
Repeated for every single method...
I wanted to initially keep the client like this - stateless and static and have only state objects that hold the actual state as there could be many connections to the server with various states. By that I wanted to avoid having the client as an object and both holding the state and performing the calls to the server. The problem is that this approach is just...dirty I guess. What would be a more DRY, readable and sustainable way of doing this?