Skip to content

Instantly share code, notes, and snippets.

@diegolucasb
Created July 9, 2018 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegolucasb/d6156d80b651229865bb6ffb2ae2a38e to your computer and use it in GitHub Desktop.
Save diegolucasb/d6156d80b651229865bb6ffb2ae2a38e to your computer and use it in GitHub Desktop.
package stone.com.br.slingkotlinsdk.builderpattern
/**
* Created by diegolucasb on 09/07/18.
* Copyright (c) Stone Co. All rights reserved.
* lucas.amaral@stone.com.br
*/
class SlingSDK(
url: String,
headers: Map<String, String>? = null,
authenticationToken: String? = null) {
private constructor(builder: Builder): this(builder.url, builder.headers, builder.authenticationToken)
companion object {
inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build()
}
lateinit var merchant: MerchantService
private set
class Builder {
var url: String = "" //BuildConfig.DEFAULT_URL
var headers: Map<String, String>? = null
var authenticationToken: String? = null
fun build() = SlingSDK(this).apply {
//injectors
merchant = Merchant(Contact())
}
}
class Merchant(
val contact: Contact,
override var url: String = ""): MerchantService()
class Contact: ContactsService {
override fun list() {
}
override fun saveOrUpdate() {
}
override fun delete() {
}
}
abstract class MerchantService: Connection()
interface ContactsService: BaseService
interface BaseService {
fun list()
fun saveOrUpdate()
fun delete()
}
abstract class Connection {
abstract var url: String
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment