diff --git a/src/main/kotlin/Homework2 Builder.kt b/src/main/kotlin/Homework2 Builder.kt new file mode 100644 index 0000000..aff0f9c --- /dev/null +++ b/src/main/kotlin/Homework2 Builder.kt @@ -0,0 +1,58 @@ +class BilderCocktail (var composition: String = "drink") + + + class DrinkBuilder { + private var drink = BilderCocktail() + + fun reset() = apply { + drink = BilderCocktail() + } + + fun build(): BilderCocktail { return drink } + + fun addWater() = apply { + drink.composition += "Water" + } + + fun addIce() = apply { + drink.composition += "ICE" + } + fun addVodka() = apply { + drink.composition += "VODKA" + } + + fun addTomato() = apply { + drink.composition += "Tomato" + } + + fun addWhisky() = apply { + drink.composition += "Whisky" + } + + fun addCocaCola() = apply { + drink.composition += "CocaCola" + } + + + } + + class Director() { + fun makeDrink1(builder: DrinkBuilder): BilderCocktail { + return builder + .reset() + .addWhisky() + .addCocaCola() + .addWater() + .addIce() + .build() + } + + fun makeBloodMary(builder: DrinkBuilder): BilderCocktail { + return builder + .reset() + .addVodka() + .addTomato() + .addWater() + .build() + } + } diff --git a/src/main/kotlin/Homework2 Command.kt b/src/main/kotlin/Homework2 Command.kt new file mode 100644 index 0000000..2e77e56 --- /dev/null +++ b/src/main/kotlin/Homework2 Command.kt @@ -0,0 +1,49 @@ +interface Command { + fun execute() +} +class Alfavit { + fun firstlit() { + println("А") + } + fun secondlit() { + println("Б") + } + fun thirdlit() { + println("В") + } + +} +class FirstLit(private val string: Alfavit) : Command { + override fun execute() { + string.firstlit() + } +} +class SecondLit(private val string: Alfavit) : Command { + override fun execute() { + string.secondlit() + } + +} +class ThirdLit(private val string: Alfavit) : Command { + override fun execute() { + string.thirdlit() + } +class Invoker (var command: Command) { + fun doExecute() { + command.execute() + } +} +fun main() { + val alfavit = Alfavit() + val firstLit = FirstLit(alfavit) + val secondLit = SecondLit(alfavit) + val thirdLit = ThirdLit(alfavit) + val invoker = Invoker(firstLit) + invoker.doExecute() + invoker.command = secondLit + invoker.doExecute() + invoker.command = thirdLit + invoker.doExecute() + +} +} diff --git a/src/main/kotlin/Homework2 Decorator.kt b/src/main/kotlin/Homework2 Decorator.kt new file mode 100644 index 0000000..a93e54c --- /dev/null +++ b/src/main/kotlin/Homework2 Decorator.kt @@ -0,0 +1,30 @@ +class decorator { + interface Drink { + fun getComposition(): String + } + + class Cocktail: Drink { + override fun getComposition(): String { + return "Cocktail" + } + } + + class WithVodka(private val drink: Drink): Drink { + override fun getComposition(): String { + return drink.getComposition() + "Vodka" + } + } + + class WithWiskey(private val drink: Drink): Drink { + override fun getComposition(): String { + return drink.getComposition() + "Wiskey" + } + } + + class WithIce(private val drink: Drink): Drink { + override fun getComposition(): String { + return drink.getComposition() + "with Ice" + } + } + +} diff --git a/src/main/kotlin/Homework2 Singletone.kt b/src/main/kotlin/Homework2 Singletone.kt new file mode 100644 index 0000000..092bd11 --- /dev/null +++ b/src/main/kotlin/Homework2 Singletone.kt @@ -0,0 +1,39 @@ +// class Singl { +// object ManagerDriver{ +// init { +// println("Manager Initialized: $this") +// } +// fun log():ManagerDriver = apply { println("Manager Driver: $this") } +// } +// } + +// class Test{ +// @org.junit.jupiter.api.Test +// fun testsingl(){ +// println("Start") +// val ManagerDriver1:Singl.ManagerDriver = Singl.ManagerDriver.log() +// val ManagerDriver2:Singl.ManagerDriver = Singl.ManagerDriver.log() +// } +// } + +package ru.otus.empty + +class Singl1 private constructor() { + + init { + println("Singl1 done") + } + + companion object { + val instance: Singl1 by lazy { + Singl1() + } + } + + +} +fun main() { + + val testSingl1 = Singl1.instance + +}