Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
Birthday Greetings
|
Learn Windows 7: What are the Technology advancements in on mobile gaming? This resource will provide information about the advancements that are available in the mobile gaming.
Resources » Articles » .NET Framework »
The Common Type System(CTS) benefits
|
A small intro about CTS and its common methods
Common Type System
One of the key features of any language or run-time environment is its support for types.
The CTS provides every language running on the .NET platform with a base set of data types. A language that makes available a limited number of types or that limits the programmer's ability to extend the language's built-in types isn't a language with a long life expectancy. However, having a unified type system has many other benefits as well.
- Every thing in the CTS is an object. - The CTS is responsible for defining the types that can be used across the .NET languages. - All objects implicitly derive from a single base class defined as a part of the CTS. This base class is called system.object. - The CTS types are value types and reference types.
Language Interoperability
The CTS plays an integral role in allowing language interoperability because it defines the set types that a .NET compiler must support in order to interoperate with other languages. The CTS itself is defined in the Common Language Specification (CLS).
The CLS defines a single set of rules for every .NET compiler, ensuring that each compiler will output code that interacts with the CLR consistently. One of the CLS requirements is that the compiler must support certain types defined in the CTS.
The benefit being that because all .NET languages are using a single type system, you are assured that objects and types created in different languages can interact with one another in a seamless manner. It's this CTS/CLS combination that helps make language interoperability more than just a programmer's dream.
Singly Rooted Object Hierarchy
As I mentioned earlier, an important CTS characteristic is the singly rooted object hierarchy. In the .NET Framework, every type in the system derives from the System.Object base class. An important diversion from the C++ language, in which there is no implied base class for all classes, this single base class approach is endorsed by OOP theorists and is implemented in most mainstream object-oriented language. The benefits to a singly rooted hierarchy aren't immediately apparent, but over time you'll come to question how languages were designed before this type of hierarchy was adopted.
A singly rooted object hierarchy is the key to a unified type system because it guarantees that each object in the hierarchy has a common interface and therefore everything in the hierarchy will ultimately be of the same base type. One of the main drawbacks of C++ is its lack of support for such a hierarchy. Let's consider a simple example to see what I mean.
Say you've built up an object hierarchy in C++ based on a base class of your own making. We'll call this base class CppFoo. Now say you want to integrate with another object hierarchy whose objects all derive from a base class called CppBar. In this example, the object hierarchies have incompatible interfaces and it's going to require a lot of effort to integrate these two hierarchies. You might have to use some sort of wrapper class with aggregation or use multiple inheritance to make this work.
With a singly rooted hierarchy, compatibility is not an issue because each object has the same interface (inherited from System.Object). As a result, you know that each and every object in your hierarchy—and, crucially, in the hierarchies of third-party .NET code—has a certain minimal set of functionality.
Type Safety
The last benefit of the CTS 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.
Methods of CTS:
Public methods:
- Boolean Equals(Object): It is used to test equality with another object.
- Int 32 Get Hash Code( ): It generates a number corresponding to the value of an object. If two objects of the same type are equal, then they must return the same hash code. This value is used extensively by the sorting algorithms implemented in System.Collections.
- Type GetType( ): Gets a Type Object that can be used to access metadata associated with the type and as a starting point for navigating the object heirarchy exposed by the Reflection API.
- String ToString( ): The default implementation returns the fully qualified name of the class of the object. This method is often overridden to output data that is more meaningful to the type.
Protected methods:
- void finalize( ): This method is called by the runtime to allow for cleanup prior to garbage collection.
- Object MemberwiseClone: This member represents a shallow copy of the object containing references to other objects that does not include copies of the objects referenced.
|
|
Responses to the resource: "The Common Type System(CTS) benefits"
|
| Author: lingesh 21 Oct 2008 | Member Level: Silver Points : 0 | Nice... good one
|
|