Commit 229c70ec authored by Javier Hernández's avatar Javier Hernández 🤓

ChocolatesBuilder

- Added ChocolatesFactory
- Deleted CandyFactory, Candy and ChocolateBar, now we use a ChocolatesBuilder instead the factory
parent 59611eaa
package com.lm.sales.builders
import com.lm.sales.model.Presentation
import com.lm.sales.model.foods.Chocolates
import com.lm.sales.model.music.CD
class ChocolatesBuilder {
private lateinit var name: String
private lateinit var manufacturer: String
private lateinit var presentation: Presentation
private var isImported: Boolean = false
private var basePrice: Double = 0.0
fun withName(name: String): ChocolatesBuilder {
this.name = name
return this
}
fun withManufacturer(manufacturer: String): ChocolatesBuilder {
this.manufacturer = manufacturer
return this
}
fun withPresentation(presentation: Presentation): ChocolatesBuilder {
this.presentation = presentation
return this
}
fun isImported(imported: Boolean): ChocolatesBuilder {
this.isImported = imported
return this
}
fun withBasePrice(price: Double): ChocolatesBuilder {
this.basePrice = price
return this
}
fun build(): Chocolates {
return Chocolates(name, manufacturer, presentation, isImported, basePrice)
}
}
\ No newline at end of file
package com.lm.sales.factories
class CandyFactory {
// fun getCandy(type: Candy.CandyType): Candy {
//
// return if (type.equals(Candy.CandyType.chocolates)) {
// Chocolates()
// } else {
// ChocolateBar()
// }
//
// }
}
\ No newline at end of file
package com.lm.sales.factories package com.lm.sales.factories
/**
* Factory to create the recipes
*
* We use a factory but in this case that we only have one type of [Recipe] we could use a builder
*
* @j.hernandezs
*/
class RecipeFactory { class RecipeFactory {
} }
\ No newline at end of file
...@@ -14,7 +14,7 @@ interface Product { ...@@ -14,7 +14,7 @@ interface Product {
} }
enum class Presentation { enum class Presentation {
box, bottle, packet box, bottle, packet, bar
} }
data class Taxes(var taxesAmount: Double = 0.0, data class Taxes(var taxesAmount: Double = 0.0,
......
package com.lm.sales.model.foods
abstract class Candy(type: CandyType) : Foods {
abstract val type: CandyType
// ...
enum class CandyType {
chocolates, candyBar, bubbleGums, candies
}
}
package com.lm.sales.model.foods
import com.lm.sales.model.Presentation
import com.lm.sales.model.Taxes
/**
* Chocolate bar implementation of [Candy] [Foods] interfaces
*
*/
data class ChocolateBar (override val name: String,
override val type: Candy.CandyType,
override val manufacturer: String,
override val presentation: Presentation,
override val imported: Boolean,
override val basePrice: Double,
override var taxes: Taxes?): Candy(type)
...@@ -4,13 +4,12 @@ import com.lm.sales.model.Presentation ...@@ -4,13 +4,12 @@ import com.lm.sales.model.Presentation
import com.lm.sales.model.Taxes import com.lm.sales.model.Taxes
/** /**
* Chocolates implementation of [Candy] [Foods] interfaces * Chocolates implementation of [Foods] interface
* *
*/ */
data class Chocolates (override val name: String, data class Chocolates (override val name: String,
override val type: Candy.CandyType,
override val manufacturer: String, override val manufacturer: String,
override val presentation: Presentation, override val presentation: Presentation,
override val imported: Boolean, override val imported: Boolean,
override val basePrice: Double, override val basePrice: Double,
override var taxes: Taxes?): Candy(type) override var taxes: Taxes? = null): Foods
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment