|
OOPS - Object Oriented Programming Languages & Systems. Class - A class is an organized store-house in Using inhertance, we may assign different traits to different A class may contain class members like fields, properties, Public Class SampleClass Class members - The different types of entities in a class, Object - An object is an instance of a class. This instance Dim objSampleObject as SampleClass Structure - It is a bit similar to a class. Semantically, Public Structure Student Dim objStud as Student Here, note that the object objStud is not exactly an instance, Public Class ClassCalc as double) as Double Now, lets make use of the method FnAdd defined in the class Dim objX as ClassCalc Property - A property is a thing that describes the features of an object. A property is a piece of data contained within a class that has an exposed interface for reading/writing. Looking at that definition, you might think you could declare a public variable in a class and call it a property. While this assumption is somewhat valid, the true technical term for a public variable in a class is a field. The key difference between a field and a property is in the inclusion of an interface. We make use of Get and Set keywords while working with Private _Color As String Event - An action that an object does. When something happens, we say an event has happened. For example, when a button is clicked, we say it is the click( ) event. When a mouse hovers on an image, we say the mouseover( ) event has taken place. Access Modifiers - Keywords used to vary the way members of a class are used. Following are different types... 1) Public - These classes can be used anywhere in the code. Available only to code outside our class 2) Private - These classes are accessible only within their Available only to code inside our class 3) Protected - These classes extend the accessibility of their Available only to classes that inherit from our class 4) Friend - Friend access means that elements are accessible only within the program. Friend is the default access modifer for any class that does not have a modifier. Available only to code within our project/component 5) Protected Friend - Available only to classes that inherit from our class (in any project) or to code within our project/component. This is a combination of Protected and Friend. Default - A Default property is a single property of a class that can be set as the default. This allows developers that use your class to work more easily with your default property because they do not need to make a direct reference to the property. Default properties cannot be initialized as Shared or Private and all must be accepted at least on argument or parameter. Default properties do not promote good code readability, so use this option sparingly. Overloads - The Overloads property allows a function to be Shared -The Shared keyword is used in an inherited or base class to define a property or method as being shared among all instances of a given class. If multiple instances of a class with shared properties or methods are loaded, the shared properties or methods will provide the same data across each instance of the class. When one class alters the value for a shared property, all instances of that class will reflect the change. Shared properties of all instances of the class Overridable -The Overridable keyword is used when defining a property or method of an inherited class, as overridable by the inheriting class. Overides - The Overides keyword allows the inheriting class to disregard the property or method of the inherited class and implements ts own code. NotOverridable - The NotOverridable keyword explicitly declares a property or method as not overridable by an inheriting class, and all properties are "not overridable" by default. The only real advantage to using this keyword is to make your code more readable. MustOverride - The MustOverride keyword forces the inheriting class to implement its own code for the property or method. Shadows - The Shadows keyword will effectively hide all of the other methods in the baseclass. It is like forcefully getting rid of the overloading that has been done on the methods of the base class. 'This is the Base Class Public Sub MyProc(ByVal st As String) 'This is the Child Class Overloads Sub MyProc(ByVal ch As Char) When we execute the following code... ' prints out "String in Parent is Hello Wazzup!" ' prints out "Number in Child is 12" ' prints out "Character in DerivedClass is B" When we use Shadows keyword... Dim c2 As New DerivedClass2() Constructor - When a class instance is created in our code, Dim objSampleObject as New SampleClass We can add parameters to the constructors. This was'nt allowed in VB6. We can overload the constructors, change the order of parameters, datatypes of parameters which ultimately change the way the constructor works whenever an instance of that class is invoked. Also note that a constructor can have any access modifier. If Public Class ClassA However, when the constructor is added with parameters, the following code is generated... Public Class ClassA When a child class' object is declared, the child class Public Class Books Public Sub myProc() Public Class Authors : Inherits Books When the Authors class' constructor is invoked, like in the Dim author As Authors The result on the console will be... Book's constructor. If the base class does'nt have a no-argument constructor, then it would result in a compiler error. Hence, we need to use the MyBase keyword with the constructor. Our child class will look like this... Public Class Authors : Inherits Books If a class is not inheriting from any base class, then it will Base class constructor is invoked. Abstract Class - They are classes that cannot be instantiated. We cannot create an object from such a class for use in our program. We can use an abstract class as a base class, creating new classes that will inherit from it. Creating an abstract class with a certain minimum required level of functionality gives us a defined starting point from which we can derive non-abstract classes. An abstract class may contain abstract methods & non-abstract methods. When a class is derived from an abstract class, the derived class must implement all the abstract methods declared in the base class. We may use accessibility modifiers in an abstract class (unlike in Interfaces). An abstract class can inherit from a non-abstract class. In C++, this concept is known as pure virtual method. Interface - its a kind of class, that has only methods, do not have code, just the definition of the methods. Also, the interface can't be instantiated. Its an abstract class with public abstract methods, all of which must be implemented in the inherited classes. All methods in an interface are public, no other access modifier is used. It is public by default. Classes can contain code, but interface dont. However, classes that implement an interface do contain code. Keep in mind that there are no instances of interfaces in VB .NET. Every instance is a type that implements an interface, but is itself not an instance of the interface. Also note, in an interface, all methods must be abstract (which is not necessary in an abstract class). 'VB .NET Interface To use members of an interface, we make use of the implements keyword. Public Class Employee
Boxing & Unboxing - Value Types are stored on the stack and Reference types are stored on the heap. The conversion of value type to reference type is known as Boxing. Converting reference type back to value type Value Types - Value types are primitive types that are mapped directly to the FCL. Like Int32 maps to System.Int32, double maps to System.double. Reference Types - Reference Types are different from value types in such a way that memory is allocated to them from the heap. All the classes are of reference type. C# new operator returns the memory address of the Partial Class - This concept has been introduced in .NET framework 2.0. They give you the ability to split a single class into more than one source code (.cs or .vb) file. Here's what a partial class looks like when it's split over two files... // Stored in file MyClass1.cs When you build the application, Visual Studio .NET tracks down each piece of Partial classes don't offer much in the way of solving programming problems, but they can be useful if you have extremely large, unwieldy classes. (Of course, this might be a sign that you haven't properly factored your problem, in which case you should really break your class down into separate classes.) The real purpose of partial classes in .NET is to hide automatically generated designer code. |
