Kotlin Design Patterns and Best Practices
eBook - ePub

Kotlin Design Patterns and Best Practices

Alexey Soshin, Anton Arhipov

  1. 356 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Kotlin Design Patterns and Best Practices

Alexey Soshin, Anton Arhipov

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Future-proof your applications with best practices and design patterns in KotlinKey Features• Understand traditional and modern design patterns to improve the design of your application• Combine the benefits of object-oriented, functional, reactive, and concurrent programming• Choose the best microservices architecture and frameworks for your web applicationBook DescriptionThis book shows you how easy it can be to implement traditional design patterns in the modern multi-paradigm Kotlin programming language, and takes you through the new patterns and paradigms that have emerged. This second edition is updated to cover the changes introduced from Kotlin 1.2 up to 1.5 and focuses more on the idiomatic usage of coroutines, which have become a stable language feature. You'll begin by learning about the practical aspects of smarter coding in Kotlin, as well as understanding basic Kotlin syntax and the impact of design patterns on your code. The book also provides an in-depth explanation of the classical design patterns, such as Creational, Structural, and Behavioral families, before moving on to functional programming. You'll go through reactive and concurrent patterns, and finally, get to grips with coroutines and structured concurrency to write performant, extensible, and maintainable code. By the end of this Kotlin book, you'll have explored the latest trends in architecture and design patterns for microservices. You'll also understand the tradeoffs when choosing between different architectures and make informed decisions. What you will learn• Implement all the classical design patterns using the Kotlin programming language• Apply reactive and concurrent design patterns to make your application more scalable• Discover best practices in Kotlin and explore its new features• Understand the key principles of functional programming and learn how they apply to Kotlin• Find out how to write idiomatic Kotlin code and learn which patterns to avoid• Harness the power of Kotlin to design concurrent and reliable systems with ease• Create an effective microservice with Kotlin and the Ktor frameworkWho this book is forThis book is for developers who want to apply design patterns they've learned from other languages in Kotlin and build reliable, scalable, and maintainable applications. You'll need a good grasp on at least one programming language before you get started with this book. Java or design patterns will be particularly useful, but you'll still be able to follow along if you code in other languages.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Kotlin Design Patterns and Best Practices è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Kotlin Design Patterns and Best Practices di Alexey Soshin, Anton Arhipov in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Programming in Java. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2022
ISBN
9781801816281
Edizione
2

Section 1: Classical Patterns

In this section, we will cover the basic syntax of the Kotlin programming language and the implementation of all the classical design patterns in Kotlin.
The classical design patterns deal with three major problems in system design: how to create objects efficiently, how to encapsulate object hierarchies, and how to make object behavior more dynamic.
We'll discuss which design patterns come as part of the language, and how to implement those that don't.
This section comprises the following chapters:
  • Chapter 1, Getting Started with Kotlin
  • Chapter 2, Working with Creational Patterns
  • Chapter 3, Understanding Structural Patterns
  • Chapter 4, Getting Familiar with Behavioral Patterns

Chapter 1: Getting Started with Kotlin

The bulk of this chapter will be dedicated to basic Kotlin syntax. It is important to be comfortable with a language before we start implementing any design patterns in it.
We'll also briefly discuss what problems design patterns solve and why you should use them in Kotlin. This will be helpful to those who are less familiar with the concept of design patterns. But even for experienced engineers, it may provide an interesting perspective.
This chapter doesn't aim to cover the entire language vocabulary but to get you familiar with some basic concepts and idioms. The following chapters will expose you to even more language features as they become relevant to the design patterns that we'll discuss.
In this chapter, we will cover the following main topics:
  • Basic language syntax and features
  • Understanding Kotlin code structure
  • Type system and null safety
  • Reviewing Kotlin data structures
  • Control flow
  • Working with text and loops
  • Classes and inheritance
  • Extension functions
  • Introduction to design patterns
By the end of this chapter, you'll have a knowledge of Kotlin's basics, which will be the foundation for the following chapters.

Technical requirements

To follow the instructions in this chapter, you'll need the following:
  • IntelliJ IDEA Community Edition (https://www.jetbrains.com/idea/download/)
  • OpenJDK 11 or higher (https://openjdk.java.net/install/)
The code files for this chapter are available at https://github.com/PacktPublishing/Kotlin-Design-Patterns-and-Best-Practices/tree/main/Chapter01.

Basic language syntax and features

Whether you come from Java, C#, Scala, or any other statically typed programming language, you'll find Kotlin syntax quite familiar. This is not by coincidence but to make the transition to this new language as smooth as possible for those with previous experience in other languages. Besides that familiarity, Kotlin brings a vast amount of features, such as better type safety. As we move ahead, you'll notice that all of them are attempting to solve real-world problems. That pragmatic approach is remarkably consistent across the language. For example, one of the strongest benefits of Kotlin is complete Java interoperability. You can have Java and Kotlin classes alongside each other and freely use any library that is available in Java for a Kotlin project.
To summarize, the goals of the language are as follows:
  • Pragmatic: Makes things we do often easy to achieve
  • Readable: Keeps a balance between conciseness and clarity on what the code does
  • Easy to reuse: Supports adapting code to different situations
  • Safe: Makes it hard to write code that crashes
  • Interoperable: Allows the use of existing libraries and frameworks
This chapter will discuss how these goals are achieved.

Multi-paradigm language

Some of the major paradigms in programming languages are procedural, object-oriented, and functional paradigms.
Being pragmatic, Kotlin allows for any of these paradigms. It has classes and inheritance, coming from the object-oriented approach. It has higher-order functions from functional programming. You don't have to wrap everything in classes if you don't want to, though. Kotlin allows you to structure your entire code as just a set of procedures and structs if you need to. You will see how all these approaches come together, as different examples will combine different paradigms to solve the problems discussed.
Instead of covering all aspects of a topic from start to finish, we will be building the knowledge as we go.

Understanding Kotlin code structure

The first thing you'll need to do when you start programming in Kotlin is to create a new file. Kotlin's file extension is usually .kt.
Unlike Java...

Indice dei contenuti