Let’s start with some really basic examples. It’s Hello World! time.
Implement method present in class Hello so that it conforms to outputs defined in HelloSpec.
Hello().present("world")
should output
Hello world
Definition of done: HelloSpec test must pass.
Use data class for implementing Person as a simple POKO (Plain Old Kotlin Object ;)).
It should have these properties:
firstName: String
lastName: String
age: Int
hobbies: List<String>
Definition of done: DataClassesSpec test must pass.
Reference: https://kotlinlang.org/docs/reference/data-classes.html
This example should give you an overview on what’s the Kotlin’s approach to inheritance. The main idea is that all classes are by default final, as well as all methods. To make class extendable you must mark it as open (or abstract if you want it to be abstract) and define all overridden methods by override keyword.
Wire up the class hierarchy defined in Inheritance.kt file as follows:
TextFile and BinaryFile are FileResourcesFileResource cannot be instantiatedBinaryFile is StreamableFileResource.toFile() to your liking.Definition of done: Just make sure you understand the essence.
Reference: https://kotlinlang.org/docs/reference/classes.html
When using Kotlin you will be encouraged to use immutable* structures whenever possible (e.g. prefer listOf over arrayListOf). Also, working with collection transformations, map-reducing values, filtering and so on is fairly easy and extremely readable.
Pro tip: Use the it keyword in lambdas to reference single parameter of a function
There are three extension functions defined on the lists.
Implement them according to description in FunWithCollections.kt.
Definition of done: FunWithCollectionsSpec tests must pass.
*immutable-ish, based on opiniated experts’ agreement
Let’s start with some really basic examples. It’s Hello World! time.
Implement method present in class Hello so that it conforms to outputs defined in HelloSpec.
Hello().present("world")
should output
Hello world
Definition of done: HelloSpec test must pass.
Use data class for implementing Person as a simple POKO (Plain Old Kotlin Object ;)).
It should have these properties:
firstName: String
lastName: String
age: Int
hobbies: List<String>
Definition of done: DataClassesSpec test must pass.
Reference: https://kotlinlang.org/docs/reference/data-classes.html
This example should give you an overview on what’s the Kotlin’s approach to inheritance. The main idea is that all classes are by default final, as well as all methods. To make class extendable you must mark it as open (or abstract if you want it to be abstract) and define all overridden methods by override keyword.
Wire up the class hierarchy defined in Inheritance.kt file as follows:
TextFile and BinaryFile are FileResourcesFileResource cannot be instantiatedBinaryFile is StreamableFileResource.toFile() to your liking.Definition of done: Just make sure you understand the essence.
Reference: https://kotlinlang.org/docs/reference/classes.html
When using Kotlin you will be encouraged to use immutable* structures whenever possible (e.g. prefer listOf over arrayListOf). Also, working with collection transformations, map-reducing values, filtering and so on is fairly easy and extremely readable.
Pro tip: Use the it keyword in lambdas to reference single parameter of a function
There are three extension functions defined on the lists.
Implement them according to description in FunWithCollections.kt.
Definition of done: FunWithCollectionsSpec tests must pass.
*immutable-ish, based on opiniated experts’ agreement