Skip to content

Instantly share code, notes, and snippets.

@alibahaaa
Created January 18, 2023 14:37
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 alibahaaa/07147bddca17813ef9e48e62c4bba3f6 to your computer and use it in GitHub Desktop.
Save alibahaaa/07147bddca17813ef9e48e62c4bba3f6 to your computer and use it in GitHub Desktop.
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