![]() This approach claims that the software’s structure and the language it uses should be deeply connected to the business domain.įor example, if a software manages a cargo fleet of vessels, there will be concepts like “voyage”, “leg”, “vessel”, “load” or “distance” represented by classes and methods. DDD is a software development approach that was first introduced by Eric Evans on his well known book Domain-Driven Design: Tackling Complexity in the Heart of Software. Domain-Driven Designįirst, let us rewind and talk about Domain-Driven Design and its role in order to have a better understanding of the “value” (pun intended □) that value classes bring.ĭomain-Driven Design A.K.A. The Kotlin documentation has a nice example. However, value classes introduce a new type and cannot be assigned.Ī Name type will not be the same type as a String. Therefore, we could assign a String value to a Name type alias. This means that a Name type alias is just another way to call the type String. Type aliases introduce an “alias” for an existing type. How are they different from type aliases? These type of classes are called inline classes because the compiler will “unbox” them to directly use the underlying type for performance improvement. However, wrapping a primitive type can be very costly in terms of performance. Value classes are value-based classes that wrap primitive values.Īs of now, Kotlin value classes only support wrapping one single primitive value. Kotlin has a variety of class types: class, data class, sealed class, enum class and the “new” value class. The new value class comes to solve a different problem. ![]() Some of Kotlin’s classes are already very popular like data class and sealed class. They were first introduced in Kotlin 1.2.30 as an experimental feature. Since Kotlin 1.5, the long time awaited inline value classes have finally become stable.
0 Comments
Leave a Reply. |