16 CHAPTER 1 THE PHILOSOPHY OF (Cedant web hosting) .NET
16 CHAPTER 1 THE PHILOSOPHY OF .NET CTS Class Types Every .NET-aware language supports, at the very least, the notion of a class type, which is the cornerstone of object-oriented programming (OOP). A class may be composed of any number of members (such as properties, methods, and events) and data points (fields). In C#, classes are declared using the class keyword: // A C# class type. public class Calc { public int Add(int x, int y) { return x + y; } } Chapter 4 examines the process of building CTS class types with C#; however, Table 1-2 documents a number of characteristics pertaining to class types. Table 1-2. CTS Class Characteristics Class Characteristic Meaning in Life Is the class sealed or not? Sealed classes cannot function as a base class to other classes. Does the class implement any An interface is a collection of abstract members that interfaces? provide a contract between the object and object user. The CTS allows a class to implement any number of interfaces. Is the class abstract or concrete? Abstract classes cannot be directly created, but are intended to define common behaviors for derived types. Concrete classes can be created directly. What is the visibility of this class? Each class must be configured with a visibility attribute. Basically, this trait defines if the class may be used by external assemblies, or only from within the defining assembly (e.g., a private helper class). CTS Structure Types The concept of a structure is also formalized under the CTS. If you have a C background, you should be pleased to know that these user-defined types (UDTs) have survived in the world of .NET (although they behave a bit differently under the hood). Simply put, a structure can be thought of as a lightweight class type having value-based semantics. For more details on the subtleties of structures, see Chapter 3. Typically, structures are best suited for modeling geometric and mathematical data, and are created in C# using the struct keyword: // A C# structure type. struct Point { // Structures can contain fields. public int xPos, yPos; // Structures can contain parameterized constructors. public Point(int x, int y) { xPos = x; yPos = y;} // Structures may define methods. public void Display() { Console.WriteLine(”({0}, {1}”, xPos, yPos); } }
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.