From Java Builders to Kotlin DSLs

From Java Builders to Kotlin DSLs

Android, Java, Kotlin, Tutorial
From Java Builders to Kotlin DSLs Introduction DSLs - Domain Specific Languages - are an ever trending topic in Kotlin circles. They allow us to flex some of the most exciting language features while accomplishing more readable and maintainable solutions in our code. Today I'd like to show you how to implement a certain kind of DSL - we're going to be wrapping an existing Java Builder in Kotlin. No doubt you've come across the builder pattern in Java before, for example if you're an Android developer, you must've used an AlertDialog.Builder, an OkHttpClient.Builder, or a Retrofit.Builder at some point. Wrapping a builder like this is a good exercise in just pure DSL design. All you have to worry about is designing the API you provide with your wrapper, since…
Read More
Android KTX – Android development with Kotlin

Android KTX – Android development with Kotlin

Android, Kotlin, Software Development, Teaching, Tutorial
Introduction Android KTX is an open source library or set of functionalities designed to make the Android development with Kotlin even more pleasant. You can find its website here. The abbreviation KTX stands for Kotlin Extensions, so this library is basically a set of extension functions, extension properties and other top-level functions. In this article, we take a look at what's inside this library and how we can take advantage of it. This library's goal is not to add new features to the existing Android APIs, but rather make those APIs easier to use by leveraging the features of the Kotlin language. Structure of Android KTX A very important thing to note at the beginning is that Android KTX provides functionalities which would be added to many individual projects by…
Read More