Skip to content

Instantly share code, notes, and snippets.

@alibahaaa
Created January 18, 2023 14:37
Embed
What would you like to do?
class Product {
var partA: String = ""
var partB: String = ""
var partC: String = ""
}
interface Builder {
fun buildPartA(part: String)
fun buildPartB(part: String)
fun buildPartC(part: String)
fun getResult(): Product
}
class ConcreteBuilder : Builder {
private val product = Product()
override fun buildPartA(part: String) {
product.partA = part
}
override fun buildPartB(part: String) {
product.partB = part
}
override fun buildPartC(part: String) {
product.partC = part
}
override fun getResult(): Product {
return product
}
}
class Director {
private lateinit var builder: Builder
fun setBuilder(builder: Builder) {
this.builder = builder
}
fun buildMinimalViableProduct() {
builder.buildPartA("part A")
}
fun buildFullFeaturedProduct() {
builder.buildPartA("part A")
builder.buildPartB("part B")
builder.buildPartC("part C")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment