ENGLISH

Kotlin Design Patterns and Best Practices: Build scalable applications using traditional, reactive, and concurrent design patterns in Kotlin, 2nd Edition

Book information

Publisher
Packt Publishing
Year
2022
ISBN
1801815720, 9781801815727
Language
english
Format
PDF
Filesize
3 MB (2915360 bytes)
Edition
2
Pages
356\356
Time added
2022-01-26 05:08:21

Description

Improve the scalability and maintainability of your applications by implementing a variety of design patterns using Kotlin Key FeaturesUnderstand traditional and modern design patterns to improve the design of your applicationCombine the benefits of object-oriented, functional, reactive, and concurrent programmingChoose the best microservices architecture and frameworks for your web applicationBook Description Design patterns are well-known solutions to common architectural problems as they allow you to solve many problems efficiently and create a shared vocabulary between developers. This 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, and will understand 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, as well as understanding the tradeoffs when choosing between different architectures. What you will learnImplement all the classical design patterns using the Kotlin programming languageApply reactive and concurrent design patterns to make your application more scalableDiscover best practices in Kotlin and explore its new featuresUnderstand the key principles of functional programming and learn how they apply to KotlinFind out how to write idiomatic Kotlin code and learn which patterns to avoidHarness the power of Kotlin to design concurrent and reliable systems with easeCreate an effective microservice with Kotlin and the Ktor frameworkWho this book is for This book is for developers looking to apply design patterns they've learned from other languages in Kotlin to build reliable, scalable, and maintainable applications. Prior programming knowledge is necessary to get started with this book. Experience in Java or design patterns is helpful, but not mandatory. Table of ContentsGetting Started with KotlinWorking with Creational PatternsUnderstanding Structural PatternsGetting Familiar with Behavioral PatternsIntroducing Functional ProgrammingThreads and CoroutinesControlling the Data FlowDesigning for ConcurrencyIdioms and Anti-PatternsConcurrent Microservices with KtorReactive Microservices with Vert.x Cover Title page Copyright and Credits Dedications Foreword Contributors Table of Contents Preface Section 1: Classical Patterns Chapter 1: Getting Started with Kotlin Technical requirements Basic language syntax and features Multi-paradigm language Understanding Kotlin code structure Naming conventions Packages Comments Hello Kotlin Understanding types Basic types Type inference Values Comparison and equality Declaring functions Null safety Reviewing Kotlin data structures Lists Sets Maps Mutability Alternative implementations for collections Arrays Control flow The if expression The when expression Working with text String interpolation Multiline strings Loops for-each loop The for loop The while loop Classes and inheritance Classes Interfaces Abstract classes Visibility modifiers Inheritance Data classes Extension functions Introduction to design patterns What are design patterns? Why use design patterns in Kotlin? Summary Questions Chapter 2: Working with Creational Patterns Technical requirements Singleton Factory Method Static Factory Method Abstract Factory Casts Subclassing Smart casts Variable shadowing Collection of Factory Methods Builder Fluent setters Default arguments Prototype Starting from a prototype Summary Questions Chapter 3: Understanding Structural Patterns Technical requirements Decorator Enhancing a class The Elvis operator The inheritance problem Operator overloading Caveats of the Decorator design pattern Adapter Adapting existing code Adapters in the real world Caveats of using adapters Bridge Bridging changes Type aliasing Constants Composite Secondary constructors The varargs keyword Nesting composites Facade Flyweight Being conservative Saving memory Caveats of the Flyweight design pattern Proxy Lazy delegation Summary Questions Chapter 4: Getting Familiar with Behavioral Patterns Technical requirements Strategy Fruit arsenal Citizen functions Iterator State Fifty shades of State State of the nation Command Undoing commands Chain of Responsibility Interpreter We need to go deeper A language of your own Call suffix Mediator The middleman Mediator flavors Mediator caveats Memento Visitor Writing a crawler Template method Observer Animal choir example Summary Questions Section 2: Reactive and Concurrent Patterns Chapter 5: Introducing Functional Programming Technical requirements Reasoning behind the functional approach Immutability Immutable collections The problem with shared mutable state Tuples Functions as values Learning about higher-order functions Higher-order functions in a standard library The it notation Closures Pure functions Currying Memoization Using expressions instead of statements Pattern matching Recursion Summary Questions Chapter 6: Threads and Coroutines Technical requirements Looking deeper into threads Thread safety Why are threads expensive? Introducing coroutines Starting coroutines Jobs Coroutines under the hood Setting timeouts Dispatchers Structured concurrency Summary Questions Chapter 7: Controlling the Data Flow Technical requirements Reactive principles Responsive principle Resilient principle Elastic principle Message-driven principle Higher-order functions on collections Mapping elements Filtering elements Finding elements Executing code for each element Summing up elements Getting rid of nesting Exploring concurrent data structures Sequences Channels Flows Summary Questions Chapter 8: Designing for Concurrency Technical requirements Deferred Value Barrier Using data classes as barriers Scheduler Creating your own schedulers Pipeline Composing a pipeline Fan Out Fan In Racing Unbiased select Mutex Sidekick channel Summary Questions Section 3: Practical Application of Design Patterns Chapter 9: Idioms and Anti-Patterns Technical requirements Using the scope functions Let function Apply function Also function Run function With function Type checks and casts An alternative to the try-with-resources statement Inline functions Implementing Algebraic Data Types Reified generics Using constants efficiently Constructor overload Dealing with nulls Making asynchronicity explicit Validating input Preferring sealed classes over enums Summary Questions Chapter 10: Concurrent Microservices with Ktor Technical requirements Getting started with Ktor Routing requests Testing the service Modularizing the application Connecting to a database Creating new entities Making the tests consistent Fetching entities Organizing routes in Ktor Achieving concurrency in Ktor Summary Questions Chapter 11: Reactive Microservices with Vert.x Technical requirements Getting started with Vert.x Routing in Vert.x Verticles Handling requests Subrouting the requests Testing Vert.x applications Working with databases Managing configuration Understanding Event Loop Communicating with Event Bus Sending JSON over Event Bus Summary Questions Assessments Index About Packt Other Books You May Enjoy

Similar books