If you are familiar with object-oriented programming, you know that a class defines the operations the object can perform (methods, events, or properties) and defines variables that hold the state of the object (fields). A class generally includes both definition and implementation, but a class can have one or more members that have no implementation. Class members that have no implementation are abstract members. An abstract class that has one or more abstract members is itself abstract and cannot be instantiated. Some language compilers that target the runtime allow you to mark a class as abstract even if none of its members are abstract. You can use an abstract class when you need to encapsulate a basic set of functionality that derived classes can inherit or override when appropriate.
An instance of an NGWS class is an object. You get access to an object's functionality by calling its methods and accessing its properties, events, and fields. Each language compiler chooses its own syntax for creating instances of classes.
A class can implement any number of interfaces, but it can inherit from exactly one base class. The runtime allows you to pass an instance of a class as a parameter. All non-abstract classes are required to have at least one constructor, which initializes new instances of the class.
Each language compiler that supports the runtime chooses its own syntax for indicating to the compiler that the class or class member has specific characteristics. You just use the syntax required by the language compiler and, when your code is compiled to IL, the compiler ensures that the characteristics of the class and its members are stored (as metadata) along with the implementation of the class.
The following table provides a description of some of the characteristics that the runtime allows a class to have. (Additional characteristics that are available through Attribute classes are not included in this list.) Your compiler might not make all of these characteristics available:
Class characteristic | Meaning |
---|---|
sealed | You cannot derive another class from this one. |
implements | The class fulfills the contract specified by one or more interfaces. |
abstract | You cannot create an instance of the class. If you want to use it, you must derive another class from it. |
inherits | Indicates that instances of the class can be used anywhere the base class is specified. A derived class that inherits from a base class can use the implementation of any virtual methods provided by the base class, or the derived class can override them with its own implementation. |
exported or not exported | Indicates whether a class is visible outside the assembly. |
The runtime allows you to define members of your class, such as properties, methods, fields, and events. Again, some language compilers might choose not to support all of these member types. The runtime allows class members to have the following characteristics (but language compilers are not required to support all of these characteristics):
Member characteristic | Meaning |
---|---|
abstract | This virtual method has no implementation. If you inherit from the class that it is a member of, you must implement this member if you want to instantiate the derived class. |
private, family, assembly, family and assembly, family or assembly, or public. | Defines the accessibility of the member:
private: accessible only from within the same class as the member or within a nested class. family: accessible from within the same class as the member and from subtypes that inherit from it. assembly: accessible only from within the assembly that contains the member's implementation. NGWS applications are partitioned into one or more assemblies, which establish the visibility scope for types at execution time. (For more information, see Assemblies.) family or assembly: accessible only from classes that qualify for either family or assembly access. family and assembly: accessible only from classes that qualify for both family and assembly access. public: accessible from any class. |
final | You cannot override this virtual method in a derived class. |
overrides | The virtual method's implementation replaces the implementation supplied by a member of the class from which it derives. |
static | The member belongs to the class it is defined on, not to a particular instance of the class; the member exists even if the class is not instantiated, and it is shared among all instances of the class. |
overloads | The method has the same name as another member defined in the same type, but it differs in some way from the other method(s) with the same name; for example, its parameter types, the order of parameter types, or the calling convention might be different. |
virtual | The method can be implemented by a subclass, and can be invoked either statically or dynamically. If dynamic invocation is used, the type of the instance that is used to make the call at run time determines which implementation of the method to call, instead of the type known at compile time. |
synchronized | The runtime ensures that only one thread of execution at a time can access the implementation. This characteristic can be applied to static methods. |