Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Maryam Ziyad <maryamziyadm@gmail.com>
  • Loading branch information
heshanpadmasiri and MaryamZi authored Nov 12, 2024
1 parent 087eef5 commit 79e7bf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion examples/distinct-object-types/distinct_object_types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ distinct class DistinctPerson {
}
}

// SomeWhatDistinctPerson is a subtype of DistinctPerson since inherit the same type ID via inclusion
// The `SomeWhatDistinctPerson` type is a subtype of the `DistinctPerson` type
// since it includes the `DistinctPerson` type's type IDs via inclusion.
class SomeWhatDistinctPerson {
*DistinctPerson;

public string name;

function init(string name) {
Expand Down
5 changes: 3 additions & 2 deletions examples/distinct-object-types/distinct_object_types.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# 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 ID 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`.

This way you can achieve the same behavior as a nominal type system within the Ballerina's structured type system, which is useful for things such as GraphQL API interfaces.
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`.

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.

::: code distinct_object_types.bal :::

Expand Down

0 comments on commit 79e7bf4

Please sign in to comment.