Skip to content

Instantly share code, notes, and snippets.

@madcato
Created March 12, 2018 08:16
Show Gist options
  • Save madcato/57426b3abdf65192f978c4c9d9811b00 to your computer and use it in GitHub Desktop.
Save madcato/57426b3abdf65192f978c4c9d9811b00 to your computer and use it in GitHub Desktop.
Base classes to develop a network API service client. Use as a template.
class HttpRequest {
func post() {
}
func get() {
}
}
class HttpAPI {
var request: HttpRequest
required init(_ request: HttpRequest) {
self.request = request
}
}
class Service {
var api: HttpAPI
required init(_ api: HttpAPI) {
self.api = api
}
}
class ServiceFactory {
func sampleBuilder() -> Service {
let request = HttpRequest()
let api = HttpAPI(request)
let service = Service(api)
return service
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment