Visual Basic is object-Based, which means it is a Object-Oriented Programming Language. Visual Basic .Net supports all features of OOP like Abstraction , Encapsulation , Polymorphism and Inheritance .
Traditionally, programming has placed an emphasis on logic and actions . Object oriented programming has taken a completely different direction,and will place an emphasis on objects and information . With object oriented programming, a problem will be broken down into a number of units. These units are called objects. What is Object-Oriented programming?
The foundation of OOP is the fact that it will place an emphasis on objects and classes. In Object-Oriented programming a program is divided into object and these object can communicate with each other through functions.
Objects Classes Data Abstraction Encapsulation Polymorphism Inheritance Concepts of OOP:
Object is the basic unit of object-oriented programming. Objects are identified by its unique name. An object represents a particular instance of a class . An Object is a collection of data members and associated member functions also known as methods. When a program is executed, objects interact with each other by sending messages. Objects
Objects with similar properties and methods are grouped together to form a Class . The actions that can be performed by objects becomes functions of the class and is referred to as Methods. Classes
Data Abstraction also represents the needed information in the program without presenting the details. Data Abstraction
Data Encapsulation combines data and functions into a single unit called Class. When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data Encapsulation enables the important concept of data hiding possible. Encapsulation
Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to the details. It is the characteristic of being able to assign a different meaning specifically, to allow an entity such as a variable, a function, or an object to have more than one form. Polymorphism
Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class, The new class that is formed is called derived class. Derived class is also known as a child class or sub class . Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming. Inheritance
OOPS provides a clear modular structure for programs which makes it good for defining abstract data types . OOPS makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones. OOPS provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces. Advantages of Object-Oriented Programming:
Polymorphism means many forms (ability to take more than one form). In Polymorphism poly means “multiple” and morph means “forms” so polymorphism means many forms. Polymorphism
In polymorphism we will declare methods with same name and different parameters in same class or methods with same name and same parameters in different classes. Polymorphism has ability to provide different implementation of methods that are implemented with same name.
In Polymorphism we have 2 different types they are - Compile Time Polymorphism (Called as Early Binding or Overloading or static binding) - Run Time Polymorphism (Called as Late Binding or Overriding or dynamic binding)
Compile time polymorphism means we will declare methods with same name but different signatures because of this we will perform different tasks with same method name. This compile time polymorphism also called as early binding or method overloading . Method Overloading or compile time polymorphism means same method names with different signatures (different parameters) Compile Time Polymorphism
Run time polymorphism also called as late binding or method overriding or dynamic polymorphism . Run time polymorphism or method overriding means same method names with same signatures. Run Time Polymorphism
In this run time polymorphism or method overriding we can override a method in base class by creating similar function in derived class this can be achieved by using inheritance principle and using “ overrides ” keywords.
Interfaces in VB.net are used to define the class members using a keyword Interface , without actually specifying how it should be implemented in a Class. Intefaces are examples for multiple Inheritance and are implemented in the classes using the keyword Implements that is used before any Dim statement in a class. Interfaces
Public Interface name ……methods… End Interface syntax
The keyword abstract can be used with both classes and methods in VB.NET to declare them as abstract. Abstract class
The classes, which we can't initialize, are known as abstract classes. They provide only partial implementations. But another class can inherit from an abstract class and can create their instances.
An Abstract class doesn't provide full abstraction but an interface does provide full abstraction; i.e. both a declaration and a definition is given in an abstract class but not so in an interface. Using Abstract we can not achieve multiple inheritance but using an Interface we can achieve multiple inheritance. DIFF BETWEEN AN ABSTRACT CLASS AND AN INTERFACE:
We can not declare a member field in an Interface. We can not use any access modifier i.e. public , private , protected , internal etc. because within an interface by default everything is public. An Interface member cannot be defined using the keyword static, virtual, abstract or sealed.