Vincent Tsen
Posted on May 13, 2023
Kotlin Flow, SharedFlow, MutableSharedFlow, StateFlow, MutableStateFlow and FlowCollector class diagram
This is part of the asynchronous flow series:
Part 5 - Flow, SharedFlow, StateFlow Class Diagram
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
extendsSharedFlow
interface. I thought there are completely independent.I didn't know
MutableSharedFlow
extendsFlowCollector
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()
convertsFlow
toSharedFlow
Flow.StateIn()
convertsFlow
toStateFlow
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.
Posted on May 13, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
September 16, 2023