Skip to content

Instantly share code, notes, and snippets.

Dusan Odalovic dodalovic

Block or report user

Report or block dodalovic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
dodalovic / a.State.kt
Last active Jun 20, 2019
State pattern implemented in kotlin
View a.State.kt
package patterns.head_first
class CoffeeMachine {
var state: CoffeeMachineState
var beansQuantity = 0
var waterQuantity = 0
val offState = Off(this)
val noIngredients = NoIngredients(this)
dodalovic / Decorator.kt
Last active Dec 6, 2017
Decorator pattern in Kotlin
View Decorator.kt
package patterns
interface CarService {
fun doService()
interface CarServiceDecorator : CarService
class BasicCarService : CarService {
override fun doService() = println("Doing basic checkup ... DONE")
dodalovic / h1.kts
Last active Jun 25, 2017
Overloaded constructors in Kotlin
View h1.kts
class Hotel {
val name: String
val city: String
val stars: Int
private var jimIncluded = false
constructor(name: String, city: String, stars: Int) { = name = city
this.stars = stars
dodalovic / Sealed.kt
Created Jun 14, 2017
Sealed classes kotlin
View Sealed.kt
sealed class Student(val indexNumber: String)
class GraduateStudent(indexNumber: String, val graduationYear: Int) : Student(indexNumber)
class UnderGraduateStudent(indexNumber: String, val currentGrade: Int) : Student(indexNumber)
fun main(args: Array<String>) {
val student: Student = UnderGraduateStudent("123", 3)
when (student) {
is UnderGraduateStudent -> println("UnderGraduateStudent :: indexNumber: ${student.indexNumber} :: current grade : ${student.currentGrade}")
is GraduateStudent -> println("GraduateStudent :: indexNumber: ${student.indexNumber} :: graduation year : $ { student.currentGrade}")
dodalovic / README.adoc
Last active May 30, 2017
Strategy pattern implementation in kotlin
View README.adoc

Strategy pattern implementation in kotlin ( language

make sure to have kotlinc on your $PATH


  • Without any command line arguments

package com.mydomain;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
dodalovic /
Created Mar 30, 2016
Transforming Java 8 collections - Collectors API
package rs.dodalovic.streams.collect.collectors_api;
import rs.dodalovic.fn_interfaces.predicate.persons_test.Person;
import java.util.*;
import static*;
dodalovic /
Last active Mar 17, 2016
blog - Java 8 Stream API - reduce operator
package rs.dodalovic.streams.reduce;
class Person {
private String name;
private Gender gender;
private Integer age;
public Person(String name, Gender gender, Integer age) { = name;
this.gender = gender;
dodalovic /
Last active Mar 16, 2016
Send mail via Gmail / SMTP using Apache commons mail
package rs.dodalovic.send_mail;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import javax.mail.util.ByteArrayDataSource;
import java.nio.charset.StandardCharsets;
dodalovic /
Last active Mar 9, 2016
Strategy pattern - User persistence - java 8
package rs.dodalovic.design_patterns.behavioral.strategy.user_persistence;
class User {
private final int id;
private final String username;
private final String location;
public User(int id, String username, String location) { = id;
this.username = username;
You can’t perform that action at this time.