Tuesday, 27 August 2013

OOP's Concept in C#

  Object Oriented Programming: Object Oriented Programming is a Style of programming that represents 
  a program as a system of objects and enables code-reuse.     

  OOP's Feature:   Encapsulation, Abstraction, Inheritance and Polymorphism

  Difference between Encapsulation and Abstraction (Encapsulation deliverable of abstraction)

  1. Encapsulation binds attribute & method into single unit while Abstraction provides simplest view  
  2. Encapsulation is evaluated with Implementation details while Abstraction is evaluated with Design details
  3. Example of encapsulation is CPU while example of abstraction is monitor  
  
  Inheritance : Process of acquiring attributes and behaviors from another object and extend a fields, methods,
  properties, event and constant and also main objectives to provide the idea of re-usability.

   Class A       ------------Base Class             Class B : A    ----------- B is derived class
   {                                                                 {
         public int add()                                            public string concat()          
        {                                                                  {
-             -- some code --                                                -- some code --
        }                                                                  }       
   }                                                                  }
  
  Create a instance of derived class, object b is able to access the add() method of parent class too.
  B b = new B();
  b.add();
  b.concat();

  Two type of inheritance:   1. Implementation    2. Interface 

  Tricky question
  Q. Does C# support multiple inheritance ? No but can achieve through interface inheritance

  Polymorphism: Ability to express one thing into many forms
  Type of polymorphism : 
  1. Compile Time (Static)  - Method overloading
  2. Run Time (Dynamic)    - Method overriding





   
 



  

  



                                                                      









 

No comments:

Post a Comment