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
package chap5.NestedClasses | |
import atomictest.eq | |
import chap5.NestedClasses.Game.Mark.* | |
import chap5.NestedClasses.Game.State.Finished | |
import chap5.NestedClasses.Game.State.Playing | |
import kotlin.random.Random | |
interface Game { | |
enum class State { Playing, Finished } |
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
package chap5.NestedClasses | |
import chap5.NestedClasses.Ticket.Seat.* | |
class Ticket( | |
val name: String, | |
val seat: Seat = Coach | |
) { | |
enum class Seat { | |
Coach, |
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
package chap5.NestedClasses | |
import atomictest.eq | |
interface Item { | |
val type: Type | |
data class Type(val type: String) | |
} |
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
package chap5.NestedClasses | |
interface Amphibian | |
fun createAmphibian(): Amphibian { | |
class Frog : Amphibian | |
return Frog() | |
} | |
fun main(){ |
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
package chap5.NestedClasses | |
fun localClasses() { | |
open class Amphibian | |
class Frog : Amphibian() | |
val amphibian: Amphibian = Frog() | |
} |
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
package chap5.NestedClasses | |
import atomictest.eq | |
abstract class Cleanable(val id: String) { | |
open val parts: List<Cleanable> = listOf() | |
fun clean(): String { | |
val text = "$id clean" | |
if (parts.isEmpty()) return text | |
return "${parts.joinToString( |
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
package chap5.NestedClasses | |
import atomictest.eq | |
import chap5.NestedClasses.Airport.Plane | |
class Airport(private val code: String) { | |
open class Plane { | |
// Can access private properties: | |
fun contact(airport: Airport) = | |
"Contacting ${airport.code}" |
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
package chap5.TypeCheking.typechecking3 | |
import atomictest.eq | |
import chap5.TypeCheking.name | |
interface BeverageContainer { | |
fun open(): String | |
fun pour() = "$name: Pour" | |
fun recycle(): String |
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
package chap5.TypeCheking.typechecking2 | |
import atomictest.eq | |
sealed class BeverageContainer { | |
abstract fun open(): String | |
abstract fun pour(): String | |
} | |
sealed class Can : BeverageContainer() { |
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
package chap5.TypeCheking.typechecking3 | |
import atomictest.eq | |
import chap5.TypeCheking.name | |
sealed class Shape { | |
fun draw() = "$name: Draw" | |
} | |
class Circle : Shape() |