In general, most of services will use some kind of domain entities (Abc in these examples) and will have the following data classes

In “chronological” (from client to DB) order

  • DTO

    • ph.safibank.examplemanager.controller.model.AbcDto

    • Data transfer object (DTO) used to communicate between the client and Controller class

    • DTOs should not be passed deeper to Services etc., also

  • Model

    • ph.safibank.examplemanager.model.Abc

    • Main model used for business logic (mostly in Service classes)

  • DB Entity

    • ph.safibank.examplemanager.model.entity.AbcEntity

    • Database entity model, consumed and produced by AbcRepository class

    • Should be converted to model when passed around to Services, Controllers, etc.

Conversions

We frequently use Kotlin extension functions to convert from one data class to another.

  • AbcDto.toModel()

  • Abc.toDto()

  • Abc.toEntity()

  • AbcEntity.toModel()

The convention is to have the converter function(s) present in the target class file, not the source class file.

For example: fun AbcDto.toModel(): Abc lives in the model class Abc.kt not in the DTO class AbcDto.kt