Reader small image

You're reading from  Kotlin Design Patterns and Best Practices - Third Edition

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781805127765
Edition3rd Edition
Right arrow
Author (1)
Alexey Soshin
Alexey Soshin
author image
Alexey Soshin

Alexey Soshin is a software architect with 18 years of experience in the industry. He started exploring Kotlin when Kotlin was still in beta, and since then has been a big enthusiast of the language. He's a conference speaker, published writer, and the author of a video course titled Pragmatic System Design
Read more about Alexey Soshin

Right arrow

What this book covers

Chapter 1, Getting Started with Kotlin, introduces you to the basic syntax of Kotlin and explain how design patterns can be applied effectively in Kotlin. The focus is not to cover the entire language vocabulary, but rather to provide a clear understanding of the fundamental concepts and idioms. Subsequent chapters will gradually introduce additional language features that are relevant to the design patterns being discussed. By the end of this chapter, you’ll have a strong foundation in the language and be ready to explore more advanced topics.

Chapter 2, Working with Creational Patterns, teaches you about classical creational patterns that are already embedded in the Kotlin language, as well as how to implement those that are not. These patterns focus on how and when to create objects. By mastering these patterns you will be able to manage your objects more effectively, adapt well to changes, and write more maintainable code. The chapter covers various patterns, including Singleton and Builder.

Chapter 3, Understanding Structural Patterns, introduces classical structural design patterns that can be used to extend the functionality of objects and adapt them to changes. By learning these patterns you will be able to write more robust and adaptable code. The chapter covers several patterns, including the widely used Decorator and Adapter patterns, which are essential for achieving greater flexibility and maintainability in software development.

Chapter 4, Getting Familiar with Behavioral Patterns, focuses on behavioral patterns in Kotlin, which deal with how objects interact with each other. You will learn how an object can exhibit different behaviors depending on the situation, how objects can communicate without direct knowledge of one another, and how to iterate over complex structures easily. By understanding these patterns you can write more flexible and reusable code that is easier to maintain over time.

Chapter 5, Introducing Functional Programming, this chapter presents the fundamental principles of functional programming and their connection to Kotlin. Without delving into much new syntax, we will address key concepts like data immutability and treating functions as first-class values. While these principles were crucial for grasping Kotlin’s advantages in the earlier chapters, here, we examine their significance within the realm of functional programming. Instead of examining their application in implementing design patterns, our focus will be on their essential role in crafting code that is more concise, modular, and maintainable.

Chapter 6, Threads and Coroutines, centers on efficiently managing a multitude of requests in our application. Threads are traditionally the go-to for concurrency in contemporary applications; however, Kotlin offers coroutines as a superior, more efficient option.

We’ll examine the advantages of utilizing coroutines and demonstrate their implementation for processing a high rate of requests. Furthermore, we will explore structured concurrency in Kotlin, a feature that enhances the safety and efficiency of concurrent code. A comprehensive explanation of this concept will be provided, along with insights into its application for boosting the performance of our applications.

Chapter 7, Controlling the Data Flow, covers higher-order functions that can be used with collections and concurrent data structures. We’ll also introduce Channels and Flows, which provide concurrent and reactive solutions that leverage these higher-order functions.

Chapter 8, Designing for Concurrency, explores the most widely utilized concurrency design patterns, particularly those implemented using coroutines. These patterns enable the simultaneous management of multiple tasks. We will also discuss how coroutines synchronize their execution to avert race conditions and guarantee thread safety.

Chapter 9, Idioms and Anti-patterns, is dedicated to discussing the optimal and less optimal practices of coding in Kotlin. We’ll go over what the preferred coding style for Kotlin is and identify certain coding patterns that are not recommended. Once you have completed this chapter, you should be able to produce Kotlin code that is easier to read and maintain, as well as steer clear of typical coding mistakes.

Chapter 10, Practical Functional Programming with Arrow, leverages our knowledge of Functional Programming and Coroutines from the previous parts and puts it into action using the Arrow framework. Arrow aims to provide a uniform and idiomatic functional programming experience for Kotlin developers, making it accessible to all. We’ll explore the power of Arrow in writing concise, expressive, and maintainable code. Throughout this chapter, we’ll highlight the key features and benefits of the Arrow framework, showcasing how it enhances development and enables the adoption of functional programming principles in Kotlin. With Arrow, developers can unlock the full potential of functional programming while capitalizing on the flexibility and robustness of Kotlin.

Chapter 11, Concurrent Microservices with Ktor, demonstrates how to put the knowledge learned in previous chapters into practice by building a microservice using Kotlin. We will use the Ktor framework, developed by Jetbrains, the creators of the Kotlin programming language. By following the examples in this chapter, you will be able to create your own microservices using Kotlin and Ktor.

Chapter 12, Reactive Microservices with Vert.x, explores an alternative method for building microservices with Kotlin by utilizing the Vert.x framework. Vert.x is based on reactive design patterns. We will examine the advantages and disadvantages of each approach and analyze real code examples to determine when to use each one.

Assessments, gives you the answers to the questions that follow each chapter throughout the rest of the book.

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Kotlin Design Patterns and Best Practices - Third Edition
Published in: Apr 2024Publisher: PacktISBN-13: 9781805127765

Author (1)

author image
Alexey Soshin

Alexey Soshin is a software architect with 18 years of experience in the industry. He started exploring Kotlin when Kotlin was still in beta, and since then has been a big enthusiast of the language. He's a conference speaker, published writer, and the author of a video course titled Pragmatic System Design
Read more about Alexey Soshin