builder-pattern-breakfastbuilder-sample.kt

Home   »   builder-pattern-breakfastbuilder-sample.kt

class BreakfastBuilder {
    private var eggs = false
    private var bacon = false
    private var breadSlices = 0
    private var drink = Drink.NATURAL_JUICE

    fun withEggs(): BreakfastBuilder {
        this.eggs = true
        return this
    }

    fun withBacon(): BreakfastBuilder {
        this.bacon = true
        return this
    }

    fun withBreadSlices(amount: Int): BreakfastBuilder {
        this.breadSlices = amount
        return this
    }

    fun withDrink(drink: Drink): BreakfastBuilder {
        this.drink = drink
        return this
    }

    fun build(): Meal.Breakfast = Meal.Breakfast(eggs, bacon, breadSlices, drink)
}

Leave a Reply

Your email address will not be published. Required fields are marked *