Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun main() {
- val printer = Printer.Base()
- val milk = Product.Milk.Base(60)
- val milkWithDiscount = Product.Milk.MilkWithDiscount(milk)
- val milkWithWithDiscount = Product.Milk.MilkWithDiscount(
- milkWithDiscount
- )
- milk.printPrice(printer)
- milkWithDiscount.printPrice(printer)
- milkWithWithDiscount.printPrice(printer)
- }
- interface Product {
- fun printPrice(printer: Printer)
- fun price() : Int
- interface Milk : Product {
- class Base(private val price: Int) : Milk {
- override fun printPrice(printer: Printer) = printer.print(price)
- override fun price() : Int = price
- }
- class MilkWithDiscount(private val milk: Milk) : Milk {
- override fun printPrice(printer: Printer) = printer.print(price())
- override fun price() : Int = milk.price() - 20
- }
- }
- }
- interface Printer {
- fun print(value: Int)
- class Base : Printer {
- override fun print(value: Int) = println("Price is value $value")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement