Sharing declarations Sample Clauses

Sharing declarations. J&s introduces shared classes with sharing declarations in the derived family, such as the declaration “shares A.C” in this code: class A { class C ... } // the base family class B extends A { // the derived family class C extends D shares A.C { ... } } This sharing declaration establishes a sharing relationship between classes A.C and B.C. Sharing declarations induce an equivalence relation on classes that is the reflexive, symmetric, and transitive closure of the declared sharing relationships. If two classes have a sharing relationship, they have the same set of object instances. However, subclasses of the two shared classes are not automatically shared, unless the subclasses also have appropriate sharing decla- rations. Therefore, the sharing relationship established in the above example can be represented as a relationship between two exact types, written A.C! B.C!. J&s requires that only an overriding class in a derived family (e.g., B.C) may declare a sharing relationship with the overridden class in a base family (e.g., A.C). This restriction helps keep shared classes similar to each other.