Created
September 16, 2019 11:23
-
-
Save MarcinMoskala/9f8bd6f8dd7cbbcb5477b4e89e1c0c80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Student( | |
val id: Int, | |
val name: String, | |
val surname: String | |
) | |
class StudentsFactory { | |
var nextId = 0 | |
fun next(name: String, surname: String) = | |
Student(nextId++, name, surname) | |
} | |
val factory = StudentsFactory() | |
val s1 = factory.next("Marcin", "Moskala") | |
println(s1) // Student(id=0, name=Marcin, Surname=Moskala) | |
val s2 = factory.next("Maja", "Markiewicz") | |
println(s2) // Student(id=1, name=Maja, Surname=Markiewicz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment