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 <[email protected]>
  • Loading branch information
heshanpadmasiri and MaryamZi authored Nov 13, 2024
1 parent ef0aefb commit 69c8851
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 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 @@ -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;

Expand All @@ -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) {
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion examples/distinct-object-types/distinct_object_types.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down

0 comments on commit 69c8851

Please sign in to comment.