How to read a kotlin programming pattern or diagram

A diagram of a Kotlin app is a set of promises rather than a picture of code. Boxes name the types, arrowheads show who may call whom, and small keywords such as sealed or suspend decide what the compiler will let you write. Read those marks in the right order and a tangle of arrows turns into a map with a legend.

Read the box before the name

The first question to ask of any rectangle is what kind of declaration it stands for. A plain box is a class you can construct; a box with a dotted top line or an interface label is a contract you implement; a box with object in the corner exists exactly once; a data class box promises equals, hashCode and copy for free; a sealed box is the top of a family that cannot grow outside its own file. Names are the least informative part, so cover the labels with your thumb and ask what each shape permits.

Inside the box, look at the constructor. Parameters listed beside the class name are handed over at creation, while properties declared with var can change afterwards. A box that lists only functions and no state is telling you the object is a service, not a record.

Decode the arrows, including the ones only Kotlin draws

Arrow style carries the meaning; the label is confirmation.

  • Solid line with a hollow triangle: the child inherits behaviour and must honour the parent contract.
  • Dashed line with an open head: a dependency, not ownership — the class uses the other one and could be handed a different one.
  • Filled diamond: composition, where the part has no life after the whole is destroyed.
  • An arrow marked suspend: crossing it may pause the caller, so everything on that path runs in a coroutine.
  • An arrow into Flow<T> or StateFlow<T>: many values over time instead of a single return.

Two arrows between the same pair usually mean a callback pair, such as a request going out and a result coming back. Number each one in reading order and the sequence becomes obvious.

Brackets and question marks carry the fine print

Generic parameters are not decoration. out T marks a producer, so a list of dogs can stand in for a list of animals; in T marks a consumer; a star projection says the diagram author did not need that type argument at this spot. A trailing ? is a hard rule about nullability: any box showing String? admits that some caller will eventually hand over nothing, and the diagram should show where that case is handled.

Walk a single action through the drawing

Pick one user action, such as tapping save, and follow it from the outermost box to the storage layer. At every hop check three things: does an arrow exist in that direction, is the hop suspend, and does any type change nullability. Where the path stops, the diagram is either incomplete or the design has a gap. That is the useful output of reading a diagram — not admiration of the architecture, but a list of the places where the code will make you decide something.

What does a dashed arrow usually mean in a Kotlin diagram?

It marks a dependency: the class refers to another type without owning it, so the reference normally arrives through the constructor or a parameter and can be swapped in a test.

Why do some boxes say sealed?

Because that type has a fixed set of subclasses, which lets a when expression over it be checked for completeness. Seeing one tells you the design wants exhaustive branching rather than open extension.

Read in that order — shape, arrow, bracket, then one traced action — a diagram stops being a poster and becomes a checklist for the code you are about to open.