Skip to content
Open
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
3 changes: 2 additions & 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.

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

8 changes: 8 additions & 0 deletions .idea/modules/homework2.main.iml

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

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

class Person private constructor(
val firstName: String,
val lastName: String,
val age: Int,
val address: String
) {
class Builder {
private var firstName: String = ""
private var lastName: String = ""
private var age: Int = 0
private var address: String = ""

fun setFirstName(firstName: String) = apply { this.firstName = firstName }
fun setLastName(lastName: String) = apply { this.lastName = lastName }
fun setAge(age: Int) = apply { this.age = age }
fun setAddress(address: String) = apply { this.address = address }

fun build(): Person {
return Person(firstName, lastName, age, address)
}
}
}
8 changes: 8 additions & 0 deletions src/main/kotlin/ru/otus/homework/decorator/CheeseDecorator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.otus.homework.decorator

class CheeseDecorator (pizza: Pizza) : PizzaDecorator(pizza) {
override fun makePizza(): String {
val basePizza = super.makePizza()
return "$basePizza with Cheese"
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/ru/otus/homework/decorator/MargheritaPizza.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.otus.homework.decorator

class MargheritaPizza : Pizza {
override fun makePizza(): String {
return "Margerita Pizza"
}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/ru/otus/homework/decorator/Pizza.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.otus.homework.decorator

interface Pizza {
fun makePizza(): String
}
7 changes: 7 additions & 0 deletions src/main/kotlin/ru/otus/homework/decorator/PizzaDecorator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.otus.homework.decorator

open class PizzaDecorator (private val pizza: Pizza) : Pizza {
override fun makePizza(): String {
return pizza.makePizza()
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/ru/otus/homework/singleton/Cat.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ru.otus.homework.singleton

class Cat private constructor() {
init {
println("The cat is created!")
}

fun meow() {
println("Meow!")
}

companion object {
val instance: Cat by lazy { Cat() }
}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/ru/otus/homework/team/Command.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.otus.homework.team

interface Command {
fun execute()
}
11 changes: 11 additions & 0 deletions src/main/kotlin/ru/otus/homework/team/Light.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.otus.homework.team

class Light {
fun turnOn() {
println("Light is turned on")
}

fun turnOff() {
println("Light is turned off")
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/ru/otus/homework/team/LightOffCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.otus.homework.team

class LightOffCommand (private val light: Light) : Command {
override fun execute() {
light.turnOff()
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/ru/otus/homework/team/LightOnCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.otus.homework.team

class LightOnCommand (private val light: Light) : Command {
override fun execute() {
light.turnOn()
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/ru/otus/homework/team/RemoteControl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.otus.homework.team

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