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
39 changes: 39 additions & 0 deletions src/main/kotlin/Builder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
data class Customer(
val name: String,
val timeVisit: Double,
val queueNumber: Int
)

class CustomerBuilder() {
private var name = "Какой-то покупатель"
private var timeVisit = 9.00
private var queueNumber = 0

fun setName(name: String): CustomerBuilder {
this.name = name
return this
}

fun setTimeVisit(timeVisit: Double): CustomerBuilder {
this.timeVisit = timeVisit
return this
}

fun setQueueNumber(queueNumber: Int): CustomerBuilder {
this.queueNumber = queueNumber
return this
}

fun build(): Customer {
return Customer(
name, timeVisit, queueNumber
)
}
}

fun main() {
val ordinaryCustomer: Customer = CustomerBuilder().build()
val someCustomer: Customer = CustomerBuilder().setName("Жора").setTimeVisit(12.00).setQueueNumber(1).build()
println(ordinaryCustomer.toString())
println(someCustomer.toString())
}
32 changes: 32 additions & 0 deletions src/main/kotlin/Command.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
interface Command {
fun execute()

}
class CommandWrapper() {
fun go(command: Command) = command.execute()
}

class FootballPlayer(): Command {
override fun execute() {
println("Бегу и бью")
}
}

class BasketballPlayer(): Command {
override fun execute() {
println("Прыгаю и кидаю")
}
}

class ChessPlayer(): Command {
override fun execute() {
println("Конь Е5, далее слоном шах, далее пешкой мат")
}
}

fun main() {
val commandWrapper = CommandWrapper()
commandWrapper.go(FootballPlayer())
commandWrapper.go(BasketballPlayer())
commandWrapper.go(ChessPlayer())
}
55 changes: 55 additions & 0 deletions src/main/kotlin/Decorator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
interface Lemonade {
fun getCost(): Int
fun getSugarPercent(): Double
fun getCompound(): String

}

class OrdinaryLemonade: Lemonade {
override fun getCost(): Int {
return 10
}

override fun getSugarPercent(): Double {
return 10.0
}

override fun getCompound(): String {
return "Вода, сахар, джем"
}
}

abstract class LemonadeDecorator(private val decoratedLemonade: Lemonade): Lemonade {
override fun getCost(): Int {
return decoratedLemonade.getCost()
}

override fun getSugarPercent(): Double {
return decoratedLemonade.getSugarPercent()
}

override fun getCompound(): String {
return decoratedLemonade.getCompound()
}
}

class NoSugarLemonade(decoratedLemonade: Lemonade): LemonadeDecorator(decoratedLemonade) {
override fun getCost(): Int {
return 5
}

override fun getSugarPercent(): Double {
return 0.0
}

override fun getCompound(): String {
return "Вода, джем"
}
}

fun main() {
val ordinaryLemonade = OrdinaryLemonade()
val lemonadeWithoutSugar = NoSugarLemonade(ordinaryLemonade)
println("Стоимость - ${ordinaryLemonade.getCost()}, Сахара - ${ordinaryLemonade.getSugarPercent()}, Состав - ${ordinaryLemonade.getCompound()}")
println("Стоимость - ${lemonadeWithoutSugar.getCost()}, Сахара - ${lemonadeWithoutSugar.getSugarPercent()}, Состав - ${lemonadeWithoutSugar.getCompound()}")
}
11 changes: 11 additions & 0 deletions src/main/kotlin/Singleton.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Singleton private constructor() {
companion object {
val instance: Singleton by lazy { Singleton() }
}

fun testSingleton() = println("Test Singleton")
}

fun main() {
Singleton.instance.testSingleton()
}