From 69c88517ed5fcc9aa5dcc1033658217274fe0a31 Mon Sep 17 00:00:00 2001 From: Heshan Padamsiri Date: Wed, 13 Nov 2024 08:02:19 +0530 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Maryam Ziyad --- examples/distinct-object-types/distinct_object_types.bal | 4 +++- examples/distinct-object-types/distinct_object_types.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/distinct-object-types/distinct_object_types.bal b/examples/distinct-object-types/distinct_object_types.bal index e4b1aaa06f..14c84f54fd 100644 --- a/examples/distinct-object-types/distinct_object_types.bal +++ b/examples/distinct-object-types/distinct_object_types.bal @@ -8,7 +8,7 @@ class Person { } }; -// `DistinctPerson` is a proper subtype of `Person`. +// The `DistinctPerson` type is a proper subtype of the `Person` type. distinct class DistinctPerson { public string name; @@ -32,6 +32,7 @@ class SomeWhatDistinctPerson { // EvenMoreDistinctPerson is a proper subtype of DistinctPerson since it has an additional type ID distinct class EvenMoreDistinctPerson { *DistinctPerson; + public string name; function init(string name) { @@ -42,6 +43,7 @@ distinct class EvenMoreDistinctPerson { public function main() { Person person = new ("John Smith"); io:println(person is DistinctPerson); + DistinctPerson distinctPerson = new ("Alice Johnson"); io:println(distinctPerson is Person); diff --git a/examples/distinct-object-types/distinct_object_types.md b/examples/distinct-object-types/distinct_object_types.md index 10a2d6521c..00594a2f5e 100644 --- a/examples/distinct-object-types/distinct_object_types.md +++ b/examples/distinct-object-types/distinct_object_types.md @@ -1,6 +1,6 @@ # Distinct object types -For more explicit control over object type relations you can use `distinct` object types. Each distinct object type declaration has a unique type ID. When you include a distinct object type within another object type declaration, the new type's type ID set will include the type IDs of the included type. When checking if a given object type `OSub` is a subtype of a distinct object type `OSuper` there is the additional requirement that `OSub` must contain all the type IDs of `OSuper`. +For more explicit control over object type relations you can use `distinct` object types. Each distinct object type declaration has a unique type ID. When you include a distinct object type within another object type declaration, the new type's type ID set will include the type IDs of the included type. When checking if a given object type `OSub` is a subtype of a distinct object type `OSuper` there is the additional requirement that the `OSub` type must contain all the type IDs of the `OSuper` type. This way you can achieve the same behavior as a nominal type system within Ballerina's structured type system, which is useful to support features such as GraphQL API interfaces.