Skip to content

Instantly share code, notes, and snippets.

View dodalovic's full-sized avatar

Dusan Odalovic dodalovic

View GitHub Profile
@dodalovic
dodalovic / h1.kts
Last active October 29, 2020 00:41
Overloaded constructors in Kotlin
class Hotel {
val name: String
val city: String
val stars: Int
private var jimIncluded = false
constructor(name: String, city: String, stars: Int) {
this.name = name
this.city = city
this.stars = stars
@dodalovic
dodalovic / Decorator.kt
Last active April 6, 2021 13:08
Decorator pattern in Kotlin
package patterns
interface CarService {
fun doService()
}
interface CarServiceDecorator : CarService
class BasicCarService : CarService {
override fun doService() = println("Doing basic checkup ... DONE")
@dodalovic
dodalovic / a.State.kt
Last active July 8, 2023 21:28
State pattern implemented in kotlin
package patterns.head_first
class CoffeeMachine {
var state: CoffeeMachineState
val MAX_BEANS_QUANTITY = 100
val MAX_WATER_QUANTITY = 100
var beansQuantity = 0
var waterQuantity = 0
val offState = Off(this)
val noIngredients = NoIngredients(this)