Created
January 18, 2023 14:37
-
-
Save alibahaaa/07147bddca17813ef9e48e62c4bba3f6 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
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