Created
July 9, 2018 21:31
-
-
Save diegolucasb/d6156d80b651229865bb6ffb2ae2a38e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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