Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Saturday, 20 May 2017

Introduction Of Object Oriented Programming (OOP)

 No comments   


Introduction
In this article we will learn what is the OOP language , why oop is most powerfull language in many platforms. why it is known as Object Oriented Pogramming Language and most powerfull features of OOPs. 

What is Object Oriented Programming(OOP)

As you knew already OOP is stands for Object Oriented Programming. As its name implies it is object based programming language. Everything work is done by the object. Using OOPs you have to work with Class , Object , Functions concept. 
C++ is the first OOP based language we had used in our programming.  In other languages we have to declare the DataType for our Data Structure but language who follows OOPs , also need to define the type of operation for that Data Structure by creating Functions.

What is Object
Object is a run time entity. Objects are identifies by its unique name. By using object we can access all the members variables and methods of a class. 

What is Class
In OOP Class ia collection of Objects of similar type. Once a class is declared then we can create a no of objects of that class. In other words we can say that class is a BluePrint that defines functions and different variables will be conman to all class related objects.

Understand OOPs Using Example
In order to clearly understand the object orientation model, let’s take your “hand” as an example. The “hand” is a class. Your body has two objects of the type "hand", named "left hand" and "right hand". Their main functions are controlled or managed by a set of electrical signals sent through your shoulders (through an interface). So the shoulder is an interface that your body uses to interact with your hands. The hand is a well-architected class. The hand is being reused to create the left hand and the right hand by slightly changing the properties of it.

Encapsulation
Encapsulation is a process of binding the data members and member function into a single unit. In other words It is a process of wrapping code and data together into a single unit, for example capsule which is mixture of several medicines
Example
class BankAccountPrivate
    {
        private string m_name;
 
        public string CustomerName
        {
            get { return m_name; }
            set { m_name = value; }
        }
    }
 

Inheritance
Inheritance is the process of inheriting or using a one class properties by second class. A class which inherits the methods and properties of other class is called derived or child class while other class which is inherited is called base or  parent class . It is the most Powerfull feature of OOP. Inheritance provides Re usability of code. 
Example
//Base Class
    public class TestBase
    {
        public virtual void BaseMethod()
        {
            Console.WriteLine("Base Class Called");
        }
    }
    // Derived Class
    public class TestDerived : TestBase
    {
        public override void DerivedMethod()
        {
            Console.WriteLine("Derived Class Called");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //Creating object of derived class
            TestDerived objDerived = new TestDerived();
            objDerived.BaseMethod();  // Base class callesd
            objDerived.DerivedMethod(); // Derived Class Called
            Console.ReadLine(  );  
        }
    }
 

Polymorphism
Polymorphism means one name many forms.  For example a Software Engineer can do different task at different time depends on the task assigned . Like he can do code , testing , Designing at different time based upon the task. 
There are two types of Polymorphism in OOP Language -:
1.  Compile Time Polymorphism or Early Binding
2.  Run- Time Polymorhism or Late Binding.

In Compile time Polymorphism object knows about itself at compile time.In this we can declare methods with same name but different signature at compile time . 
public class TestClass
   {
       public void SUM(int a, int b)
       {
           Console.WriteLine(a + b);
       }
       public void SUM(int a, int b, int c)
       {
           Console.WriteLine(a + b + c);
       }
   }
In this above example we have Sum named methods which has same name same return type but different signature.

Runtime Polymorhism also called dynamic polymorphism. In Runtime Polymorhism we have same name method with same signature, also known as Method Overriding.

In this method overriding we can override a method in derived class by creating a same name method in base class. For Runtime Polymorphism Inheritance is necessary.
Example
//Base Class
    public class TestBase
    {
        public virtual void Sample1()
        {
            Console.WriteLine("This is your Base Class");
        }
    }
    // Derived Class
    public class TestDerived : TestBase
    {
        public override void Sample1()
        {
            Console.WriteLine("This is your Derived Class");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            // calling the overriden method
            TestDerived objDerived = new TestDerived();
            objDerived.Sample1();
            // calling the base class method
            TestBase objBase= new   TestDerived();
            objBase.Sample1();
            Console.ReadLine();  
        }
    }


Abstraction
Abstraction is the process of showing essential features of a class and hiding non essential features. For example for using Music player on your phone you need just go to the application and start it even you don't know the actual work how it is managed internally. Or you can say that Your Cell Phone it has many features and you enjoyed them but you don't know the internal structure of your cell. All non essential features are hide from you.
Example
abstract class animal
   {
       public abstract void Run();
       public void eat()
       {
           Console.WriteLine("cat can eat");
       }
   }
   class cat : animal
   {
       public override void Run() { Console.WriteLine("cat can run"); }
   }
 

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write