Skip to content

Commit 05f9ce2

Browse files
authored
Update Serializing interfaces section in Polymorphism (#1028)
Rewrite the first paragraph in the section with more logical text.
1 parent 88e57b9 commit 05f9ce2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/polymorphism.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ the [Sealed classes](#sealed-classes) section, but here subclasses can be spread
321321
### Serializing interfaces
322322

323323
We can update the previous example and turn `Project` superclass into an interface. However, we cannot
324-
mark an interface itself as `@Serializable`.
325-
One possible practical default behaviour is to make them polymorphically serializable.
326-
Thus all interfaces are considered to be implicitly serializable with the [PolymorphicSerializer]
327-
strategy.
324+
mark an interface itself as `@Serializable`. No problem. Interfaces cannot have instances by themselves.
325+
Interfaces can only be represented by instances of their derived classes. Interfaces are used in the Kolin language to enable polymorphism,
326+
so all interfaces are considered to be implicitly serializable with the [PolymorphicSerializer]
327+
strategy. We just need to mark thier implementing classes as `@Serializable` and register them.
328328

329329
<!--- INCLUDE
330330
import kotlinx.serialization.modules.*
@@ -348,7 +348,7 @@ interface Project {
348348
class OwnedProject(override val name: String, val owner: String) : Project
349349
```
350350

351-
It means that if we declare `data` with the type of `Project` we can simply call `format.encodeToString` as we did before.
351+
Now if we declare `data` with the type of `Project` we can simply call `format.encodeToString` as before.
352352

353353
```kotlin
354354
fun main() {

0 commit comments

Comments
 (0)