DEV Community

Cover image for Flow, SharedFlow, StateFlow Class Diagram
Vincent Tsen
Vincent Tsen

Posted on • Originally published at vtsen.hashnode.dev

1 1

Flow, SharedFlow, StateFlow Class Diagram

Kotlin Flow, SharedFlow, MutableSharedFlow, StateFlow, MutableStateFlow and FlowCollector class diagram

This is part of the asynchronous flow series:

Since I've been playing around with asynchronous Kotlin flow in Android, I have to admit that the class relationship between all these flow classes is not clear even though I know how to use them.

Therefore, I drew this diagram below to get me to understand them.

There are a few things that I did not expect before I get to see this big picture.

  • I didn't know StateFlow extends SharedFlow interface. I thought there are completely independent.

  • I didn't know MutableSharedFlow extends FlowCollector interface.

The green boxes in the above class diagram are interfaces and the purple boxes are the implementations of those interfaces, which you rarely need to care about it.

A few quick notes about the class diagram:

  • Flow.ShareIn() converts Flow to SharedFlow

  • Flow.StateIn() converts Flow to StateFlow

The rest should be self-explanatory. To understand the usage of these interfaces in detail, you can refer to my previous articles, start with part 2.

I hope you find these class diagram helpful. Enjoy! Code examples that you can play around with:

GitHub Repository: Demo_AsyncFlow


Originally published at https://vtsen.hashnode.dev.

Sentry mobile image

Mobile Vitals: A first step to Faster Apps

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read the guide

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay