Page 20 - Open Soource Technologies 304.indd
P. 20

Unit 1: Introduction to Visual Basic



            1.4.1 Classes                                                                         Notes


            Class defines the operations an object can perform (methods, events, or properties) and defines
            a value that holds the state of the object (fields). Although a class generally includes both
            definition and implementation, it can have one or more members that have no implementation.
            An instance of a class is an object. You access an object’s functionality by calling its methods and
            accessing its properties, events, and fields.
            The Table 1.1 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 language might not make all these characteristics available.
                                    Table 1.1: Characteristics of a Class

               Characteristic                       Description
              Sealed        Specifies that another type cannot be derived from this type.
              Implements    Indicates that the class uses one or more interfaces by providing implementations
                            of interface members.
              Abstract      Specifies that you cannot create  an instance  of the class. 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 derived
                            class can override them with its own implementation.
              Exported or   Indicates whether a class is visible  outside the assembly in which it is defined.
              not exported   Applies only to top-level classes.
            Source: http://msdn.microsoft.com/en-us/library/2s9w552e%28v=vs.71%29.aspx
            Nested classes also have member characteristics. Class members that have no implementation
            are abstract members. A class that has one or more abstract members is itself abstract; new
            instances of it cannot be created. Some languages 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. Classes that are not abstract are referred to as concrete classes. A class can
            implement any number of interfaces, but it can inherit from only one base class. All classes
            must have at least one constructor, which initializes new instances of the class. Each language
            that supports the runtime provides a way to indicate that a class or class member has specific
            characteristics. When you use the syntax required by your language, the language ensures that
            the characteristics of the class and its members are stored (as metadata) along with the
            implementation of the class.

            1.4.2 Interfaces

            An interface is basically a class definition. It itself cannot be instantiated, rather it is implemented
            by other classes. Interfaces can be defined and implemented in VB6 albeit with some workarounds
            and limitations. For example, in VB6 you cannot use one variable alone to access the methods of
            the interface and of the implementing class–you have to declare two variables, one as the
            interface and the other as the implementing class and point both of them to the same instance.
            VB.NET has a different and more straightforward implementation of interfaces. Like classes,
            interfaces can be declared in any class file and are declared with a Interface End Interface statement
            block:





                                             LOVELY PROFESSIONAL UNIVERSITY                                   13
   15   16   17   18   19   20   21   22   23   24   25