-
Notifications
You must be signed in to change notification settings - Fork 0
Lab 3
This lab is designed to provide hands-on experience with object oriented programming, collections, and the standard library in Kotlin.
-
Open the lab-3 project in Android Studio
-
Open
Functions.kt
and update/implement the functions there to make the tests inFunctionTests.kt
pass -
Open
Loggers.kt
and implement the interfaces, classes, and functions required to make the tests inOOPTests.kt
pass- You'll need to implement a
Logger
interface - You'll need a
BasicLogger
Object class that implementsLogger
- You'll need a
FancyLogger
class that implementsLogger
- You'll need an extension function on the
BasicLogger
class to log multiple messages at the same time
- You'll need to implement a
-
Open
SupportedLanguages.kt
and update/implement the code to make the tests inSealedClassTests.kt
pass- You'll need to add a
InvalidNameException
andEmptyNameException
to theSupportedAndroidLanguageException
sealed class
- You'll need to add a
-
Open
CollectionsProcessing.kt
and update/implement the function to make the tests inCollectionsTests.kt
pass
- Create an
ExtraFancyLogger
class that extendsFancyLogger
. - It should specify both a
logTag
and aseparator
. - It should override the
log()
implementation to use both properties when logging the message.
Create an extension function on BasicLogger
to print all elements of a List
.
- It should take in a
List<String>
- It should print each message using
BasicLogger.log()
The Kotlin Standard Library has several helpful functions for filtering values from a collection:
-
filter{}
The generic filter function takes a lambda allowing you to specify your own filtering criteria -
filterNotNull()
Will filter out any null values
Class in Kotlin are closed for extension by default. To extend a class you must do 1 of 2 things
- Make the base class abstract
- Mark the base class as open for extension by adding the
open
modifier to the class declaration
Like classes, methods in Kotlin are closed for extension be default.
To mark a method as being open for extension in child classes, add the open
modifier to the method declaration