Skip to content
Open

Done #28

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.7.21'
id 'org.jetbrains.kotlin.jvm' version '1.9.10'
}

group 'ru.otus'
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
9
0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added build/kotlin/compileKotlin/cacheable/last-build.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
67 changes: 67 additions & 0 deletions src/main/kotlin/ru/otus/homework/Builder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ru.otus.homework

abstract class Meat
class Chicken: Meat()
class Beef: Meat()

abstract class Sauce
class CheeseSauce: Sauce()
class SpicySauce: Sauce()


interface Builder {
var name: String
var meat: Meat
var sauce: Sauce
var cost: Int
var cheese: Boolean

fun getBurger(): Burger
}

class BurgerBuilder : Builder {
override var name: String = "NoName"

override lateinit var meat: Meat

override lateinit var sauce: Sauce

override var cost: Int = 100

override var cheese: Boolean = false
override fun getBurger(): Burger {
return Burger(name, meat, sauce, cost, cheese)
}
}

data class Burger(val name: String, val meat: Meat, val sauce: Sauce, val cost: Int, val cheese: Boolean)

class Director {
fun createKfcBurger(builder: BurgerBuilder) {
builder.name = "KFC burger"
builder.cost = 150
builder.meat = Chicken()
builder.sauce = CheeseSauce()
builder.cheese = true
}
fun createMacBurger(builder: BurgerBuilder) {
builder.name = "MacDonald's Burger"
builder.cost = 120
builder.meat = Beef()
builder.sauce = SpicySauce()
builder.cheese = false
}
}

fun main() {
val director = Director()
val burgerBuilder = BurgerBuilder()
director.createKfcBurger(burgerBuilder)
val kfcBurger = burgerBuilder.getBurger()
println(kfcBurger.toString())

director.createMacBurger(burgerBuilder)
val macBurger = burgerBuilder.getBurger()
println(macBurger.toString())

}
42 changes: 42 additions & 0 deletions src/main/kotlin/ru/otus/homework/Command.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.otus.homework

interface Command {
fun execute()
}

class Light {
fun lightOn() {
println("Light is ON")
}
fun lightOff() {
println("Light is OFF")
}
}

class CommandTurnOn (private var light: Light) : Command {
override fun execute() {
light.lightOn()
}
}

class CommandTurnOff (private var light: Light) : Command {
override fun execute() {
light.lightOff()
}
}

class RemoteControl(private val command: Command) {
fun pressButton() {
command.execute()
}
}

fun main() {
val light = Light()
val lightOnCommand = CommandTurnOn(light)
val lightOffCommand = CommandTurnOff(light)
val remote = RemoteControl(lightOnCommand)
remote.pressButton()
val remote2 = RemoteControl(lightOffCommand)
remote2.pressButton()
}
43 changes: 43 additions & 0 deletions src/main/kotlin/ru/otus/homework/Decorator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ru.otus.homework

interface Coffee {
fun getCost() : Int
fun getMessage() : String
}

class SimpleCoffee : Coffee {
override fun getCost() : Int {
return 100
}

override fun getMessage() : String {
return "Coffee"
}
}

abstract class Decorator(private val decoratedCoffee: Coffee) : Coffee {
override fun getCost(): Int {
return decoratedCoffee.getCost()
}

override fun getMessage(): String {
return decoratedCoffee.getMessage()
}
}

class SugarDecorator(decoratedCoffee: Coffee) : Decorator(decoratedCoffee) {
override fun getCost(): Int {
return super.getCost() + 20
}

override fun getMessage(): String {
return super.getMessage() + " with sugar"
}
}

fun main() {
val coffee = SimpleCoffee()
val sugarCoffee = SugarDecorator(coffee)
println(sugarCoffee.getCost())
println(sugarCoffee.getMessage())
}
55 changes: 55 additions & 0 deletions src/main/kotlin/ru/otus/homework/Singleton.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ru.otus.homework

class Singleton private constructor(){
private lateinit var list: MutableList<String>
fun addValue(str: String) {
list.add(str)
}

companion object {
var tempObj: Singleton? = null
fun getInstance() : Singleton {
tempObj?.let {
return it
}
val instance = Singleton()
instance.list = mutableListOf<String>()
tempObj = instance
return instance
}
}
fun show() {
for (str in list) {
println(str)
}
}
}

object SingleTon2 {
private var list: MutableList<String> = mutableListOf<String>()
fun addValue(str: String) {
list.add(str)
}
fun show() {
for (str in list) {
println(str)
}
}
}

fun main() {
//используем класс с подробной реализацией
val db = Singleton.getInstance()
db.addValue("Denis")
db.addValue("Ivan")
val db2 = Singleton.getInstance()
db2.addValue("Petya")
db2.show()

//используем в стиле котлин
val dbKotlin = SingleTon2
dbKotlin.addValue("Java")
val dbKotlin2 = SingleTon2
dbKotlin2.addValue("Kotlin")
dbKotlin2.show()
}
5 changes: 5 additions & 0 deletions src/main/kotlin/ru/otus/homework/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.otus.homework

fun main() {
println("Hello world")
}