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

Adapter

The Adapter design pattern aims to convert one interface into another, much like the physical world examples of electrical plug adapters or USB adapters we encounter in daily life.

Imagine finding yourself in a hotel room late at night, with only 7% battery left on your phone. Your phone charger is in your office at the other end of the city, and all you have is an EU plug charger with a Mini USB cable. However, your phone requires a USB-C connection since you had to upgrade. To add to the challenge, the outlets in New York are USB-A. In this desperate situation, you urgently search for a Mini USB-to-USB-C adapter and hope you also brought your EU-to-US plug adapter. Time is running out as your battery reaches a mere 5%.

Just as adapters help us in the physical world, we can apply the same principle in code to enable compatibility between different interfaces.

Let’s explore how we can achieve this through interfaces. We start with the USPlug interface, which...

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