Type Safety
The last benefit of the CTS that I want to mention is type safety. Type safety guarantees that types are what they say they are and that only appropriate operations can be performed on a particular type. Type safety provides a number of advantages and capabilities-as described-most of which stem from the singly rooted object hierarchy.
- Every reference to an object is typed, and the object it's referencing is also typed. The CTS guarantees that a reference always points to what it implies it points to.
- Because the CTS tracks every type in the system, there's no way to trick the system into thinking that one type is actually another. This is obviously a major concern for distributed applications in which security is a priority.
- Each type is responsible for defining the accessibility of its members by specifying an access modifier. This is done on a member-by-member basis and includes allowing any access (by declaring the member public), limiting the visibility to inherited classes only (by declaring the member protected), allowing no access at all (by declaring the member private), and allowing access only to other types in the current compilation unit (by declaring the member internal). I'll discuss access modifiers in more detail in the next chapter.