Sealed Class for UML Class Diagram


#1

Just more of a curiosity… I’ve been adding some UML (via PlantUML) to my code, and am wondering how to annotate a sealed class. I can see an Enum being a valid choice, as well as an Abstract class.

Here’s my code:

/**

  • Partial states of [ScheduleViewState]
    */
    sealed class PartialScheduleViewState {

    /**

    • Reduce this state onto the [previousState], returning a new [ScheduleViewState]
      */
      abstract fun reduce(previousState: ScheduleViewState): ScheduleViewState

    /**

    • Partial state that indicates loading
      */
      class Loading : PartialScheduleViewState() {
      override fun reduce(previousState: ScheduleViewState): ScheduleViewState =
      ScheduleViewState(loading = true)
      }

    /**

    • Partial state that indicates empty data
      */
      class Empty : PartialScheduleViewState() {
      override fun reduce(previousState: ScheduleViewState): ScheduleViewState =
      ScheduleViewState(data = emptyList())
      }

}

and the UML:

@startuml
namespace state {
class ScheduleViewState {
loading: Boolean
data: List
}

    PartialScheduleViewState <|-- Loading
    PartialScheduleViewState <|-- Empty

    abstract class PartialScheduleViewState {
        abstract fun reduce(): ScheduleViewState
    }

    class Loading {
        + reduce(): ScheduleViewState
    }

    class Empty {
        + reduce(): ScheduleViewState
    }
}

@enduml

Curious to see if anyone has any opinions/thoughts…