Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Kotlin Design Patterns and Best Practices

You're reading from   Kotlin Design Patterns and Best Practices Elevate your Kotlin skills with classical and modern design patterns, coroutines, and microservices

Arrow left icon
Product type Paperback
Published in Apr 2024
Publisher Packt
ISBN-13 9781805127765
Length 474 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Alexey Soshin Alexey Soshin
Author Profile Icon Alexey Soshin
Alexey Soshin
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Section 1: Classical Patterns FREE CHAPTER
2. Getting Started with Kotlin 3. Working with Creational Patterns 4. Understanding Structural Patterns 5. Getting Familiar with Behavioral Patterns 6. Section 2: Reactive and Concurrent Patterns
7. Introducing Functional Programming 8. Threads and Coroutines 9. Controlling the Data Flow 10. Designing for Concurrency 11. Section 3: Practical Application of Design Patterns
12. Idioms and Anti-Patterns 13. Practical Functional Programming with Arrow 14. Concurrent Microservices with Ktor 15. Reactive Microservices with Vert.x 16. Assessments
17. Other Book You May Enjoy
18. Index

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 chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime