# delegates

Published articles for delegates.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Interface Delegation

DevFeed: [Interface Delegation](<https://devfeed.tech/articles/interface-delegation-39200.md>)

Original publisher: [Read original article](<https://kt.academy/article/ak-interface-delegation>)

Published: 2023-03-06T00:15:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [interface](<https://devfeed.tech/topics/interface.md>), [Inheritance](<https://devfeed.tech/topics/inheritance.md>), [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>)

Tags: [delegates](<https://devfeed.tech/tags/delegates.md>), [delegation](<https://devfeed.tech/tags/delegation.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [interface](<https://devfeed.tech/tags/interface.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [safety](<https://devfeed.tech/tags/safety.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This tutorial explains Kotlin interface delegation through the delegation pattern, composition, and comparison with inheritance. It describes how delegation reuses implementations, supports polymorphic behavior, and reduces the additional code needed when specifying a delegate.

### Source excerpt

One of the least known Kotlin features, that can be sometimes found really useful.

## Kotlin property delegates for Datastore Preferences library

DevFeed: [Kotlin property delegates for Datastore Preferences library](<https://devfeed.tech/articles/kotlin-property-delegates-for-datastore-preferences-library-26020.md>)

Original publisher: [Read original article](<https://proandroiddev.com/kotlin-property-delegates-for-datastore-preferences-library-5d4e1cdb609b?source=rss-e93d234beac6------2>)

Author: Yahor Urbanovich

Published: 2021-08-23T15:40:08Z

Content type: tutorial

Language: en

Sources: [Stories by Yahor Urbanovich on Medium](<https://devfeed.tech/sources/stories-by-yahor-urbanovich-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [kotlin-flow](<https://devfeed.tech/topics/kotlin-flow.md>), [migration](<https://devfeed.tech/topics/migration.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [delegates](<https://devfeed.tech/tags/delegates.md>), [delegation](<https://devfeed.tech/tags/delegation.md>), [deprecated](<https://devfeed.tech/tags/deprecated.md>), [flow](<https://devfeed.tech/tags/flow.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-flow](<https://devfeed.tech/tags/kotlin-flow.md>), [library](<https://devfeed.tech/tags/library.md>), [migration](<https://devfeed.tech/tags/migration.md>), [property-delegation](<https://devfeed.tech/tags/property-delegation.md>), [suspend-function](<https://devfeed.tech/tags/suspend-function.md>)

### AI overview

This tutorial explains migrating preference storage from SharedPreferences to AndroidX DataStore Preferences. It shows how Kotlin property delegation can encapsulate reading and writing values, and how Flow, coroutines, first(), and runBlocking can support single-value access despite DataStore's Flow-based API.

### Source excerpt

Kotlin delegated property for Datastore Preferences library Recently AndroidX Datastore 1.0 was released. The moment has come, it's time to migrate away from SharedPreferences. As for me, the key benefit is the built-in support of Kotlin Flow and Coroutines. Previously we had to write our own wrapper under SharedPreferences.OnSharedPreferenceChangeListener, emit changes into ConflatedBroadcastChannel and then convert it into Flow. https://medium.com/media/b5410ce9df08d9b73427a2138a6b0a8d/href Firstly, this approach produces a lot of intermediate variables. Secondly, ConflatedBroadcastChannel deprecated and should be replaced with StateFlow. In this case, DataStore comes out as the winner. The migrated to DataStore version looks clean and simple. https://medium.com/media/cce0d485e2af9941e677dc7973a54c6f/hrefRead/write single value using SharedPreferences Let's imagine, we need to store the current App theme as String. For this purpose, we need to initialize SharedPreferences, then make two functions to read and write these values. https://medium.com/media/3bc9760a22ebd1071e4dcb21eaf8d4ba/href Well, two functions it is not so bad, but we can try to merge this into single Property. https://medium.com/media/c3babbf2b6c55bb18172f66ddc825b06/href To make it fully clear and supportable we can use the Kotlin delegation feature. As we want to read and write simultaneously, ReadWriteProperty will suit our goal. https://medium.com/media/80f370a5a5735b911c75d3a0f1d22b21/href Please take a look at the final compact version, where all logic is encapsulated inside the delegate. https://medium.com/media/39b5311b04373b1f31d3030b8b083587/hrefDataStore Preferences and missing API During migration, it turned out that the library doesn't provide an API for reading a single property. DataStore proposes to use Flow for all cases. Developers are now required to read/write the value in the scope of a suspend function. https://medium.com/media/e7c4e45e239e11bc5082f3997e5280dd/href What was e

## Using Kotlin Delegated Properties to Nullify Android References and Reduce Memory Leaks

DevFeed: [Using Kotlin Delegated Properties to Nullify Android References and Reduce Memory Leaks](<https://devfeed.tech/articles/let-your-delegates-auto-nullify-references-25733.md>)

Original publisher: [Read original article](<https://blog.shreyaspatil.dev/let-your-delegates-auto-nullify-references/>)

Author: Shreyas Patil

Published: 2021-03-12T13:39:24Z

Content type: tutorial

Language: en

Sources: [Shreyas Patil's Blog](<https://devfeed.tech/sources/shreyas-patil-s-blog.md>)

Topics: [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [Android](<https://devfeed.tech/topics/android.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Jetpack](<https://devfeed.tech/topics/jetpack.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [delegates](<https://devfeed.tech/tags/delegates.md>), [fragments](<https://devfeed.tech/tags/fragments.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-beginner](<https://devfeed.tech/tags/kotlin-beginner.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>), [mobile-development](<https://devfeed.tech/tags/mobile-development.md>), [properties](<https://devfeed.tech/tags/properties.md>)

### AI overview

This tutorial explains how Kotlin property delegates can automatically nullify references in Android components. It focuses on clearing Fragment and RecyclerView.Adapter references according to lifecycle events to reduce memory leaks and boilerplate.

### Source excerpt

Learn how to use Kotlin property delegates to automatically nullify references in Android, preventing memory leaks in Fragments and Activities.

## Krate, a better SharedPreferences experience

DevFeed: [Krate, a better SharedPreferences experience](<https://devfeed.tech/articles/krate-a-better-sharedpreferences-experience-27069.md>)

Original publisher: [Read original article](<https://zsmb.co/krate-a-better-sharedpreferences-experience/>)

Author: Márton Braun

Published: 2020-09-09T16:00:00Z

Content type: tutorial

Language: en

Sources: [zsmb.co](<https://devfeed.tech/sources/zsmb-co.md>)

Topics: [Library](<https://devfeed.tech/topics/library.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [delegates](<https://devfeed.tech/tags/delegates.md>), [getting-started](<https://devfeed.tech/tags/getting-started.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.md>), [marton-braun](<https://devfeed.tech/tags/marton-braun.md>), [property](<https://devfeed.tech/tags/property.md>), [zsmb](<https://devfeed.tech/tags/zsmb.md>), [zsmb-co](<https://devfeed.tech/tags/zsmb-co.md>), [zsmb13](<https://devfeed.tech/tags/zsmb13.md>), [zsmbco](<https://devfeed.tech/tags/zsmbco.md>)

### AI overview

Krate is a Kotlin wrapper library for SharedPreferences that uses delegated properties to make persistent key-value storage simpler. The article explains its basic usage, nullability and default values, and custom implementations.

### Source excerpt

Accessing SharedPreferences using its API directly can be somewhat inconvenient. Krate is a library built on Kotlin delegates to simplify the use of SharedPreferences.

## Better Custom Views with Delegates

DevFeed: [Better Custom Views with Delegates](<https://devfeed.tech/articles/better-custom-views-with-delegates-27044.md>)

Original publisher: [Read original article](<https://web.archive.org/web/20210621155927/https://blog.autsoft.hu/better-custom-views-with-delegates/>)

Author: Márton Braun

Published: 2019-10-17T14:00:00Z

Content type: tutorial

Language: en

Sources: [zsmb.co](<https://devfeed.tech/sources/zsmb-co.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [ui](<https://devfeed.tech/topics/ui.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [code](<https://devfeed.tech/tags/code.md>), [components](<https://devfeed.tech/tags/components.md>), [delegates](<https://devfeed.tech/tags/delegates.md>), [design](<https://devfeed.tech/tags/design.md>), [design-system](<https://devfeed.tech/tags/design-system.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [ui](<https://devfeed.tech/tags/ui.md>), [ui-components](<https://devfeed.tech/tags/ui-components.md>)

### AI overview

This tutorial explains how to implement reusable custom UI components using Kotlin delegates. It uses a customizable card component as an example and discusses optional content, adaptive layout, built-in margins, XML layouts, and providing an easy-to-use API.

### Source excerpt

Reusable UI components are all the rage these days. In this article, we'll take a look at implementing custom components easily by using Kotlin's delegates.

## Kotlin Delegated Properties for Designing a Simple Android Library API

DevFeed: [Kotlin Delegated Properties for Designing a Simple Android Library API](<https://devfeed.tech/articles/delightful-delegate-design-27043.md>)

Original publisher: [Read original article](<https://web.archive.org/web/20200513142755/https://blog.autsoft.hu/delightful-delegate-design/>)

Author: Márton Braun

Published: 2019-04-11T19:00:00Z

Content type: tutorial

Language: en

Sources: [zsmb.co](<https://devfeed.tech/sources/zsmb-co.md>)

Topics: [API](<https://devfeed.tech/topics/api.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [Android](<https://devfeed.tech/topics/android.md>), [properties](<https://devfeed.tech/topics/properties.md>), [factory function](<https://devfeed.tech/topics/factory-function.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [api](<https://devfeed.tech/tags/api.md>), [api-design](<https://devfeed.tech/tags/api-design.md>), [delegates](<https://devfeed.tech/tags/delegates.md>), [factory-function](<https://devfeed.tech/tags/factory-function.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.md>), [properties](<https://devfeed.tech/tags/properties.md>)

### AI overview

This tutorial explains API design choices in the Krate Android SharedPreferences wrapper. It shows how Kotlin delegated properties can encapsulate reusable logic, persist values across application restarts, and hide concrete implementations behind a simple interface and factory function.

### Source excerpt

When developing a library, designing an easy to use API while hiding unnecessary implementation details from clients is fundamental. Let's look at some API design choices we've made for our library Krate, an Android SharedPreferences wrapper.

## Delegates vs Closure Callbacks

DevFeed: [Delegates vs Closure Callbacks](<https://devfeed.tech/articles/delegates-vs-closure-callbacks-25806.md>)

Original publisher: [Read original article](<https://www.steveonstuff.com/2018/08/16/delegates-vs-closure-callbacks>)

Author: Steve Barnegren

Published: 2018-08-16T00:00:00Z

Content type: comparison

Language: en

Sources: [Steve Barnegren](<https://devfeed.tech/sources/steve-barnegren.md>)

Topics: [Swift](<https://devfeed.tech/topics/swift.md>), [Objective-C](<https://devfeed.tech/topics/objective-c.md>)

Tags: [callback](<https://devfeed.tech/tags/callback.md>), [closure](<https://devfeed.tech/tags/closure.md>), [compare](<https://devfeed.tech/tags/compare.md>), [delegates](<https://devfeed.tech/tags/delegates.md>), [objective-c](<https://devfeed.tech/tags/objective-c.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [swift](<https://devfeed.tech/tags/swift.md>)

### AI overview

This comparison examines delegate and closure callback patterns in Swift, focusing on retain-cycle handling and managing callbacks from multiple instances. It finds delegates safer for weak-reference relationships, while closure callbacks are clearer when separating callbacks for multiple instances.

### Source excerpt

Remember how awesome the delegate pattern was in Objective-C? Enabling classes to be super reusable by delegating out the bits that you might want control over. There's a reason that it's so ubiquitous across Cocoa Touch, it's just so damn good!