Wednesday, October 1, 2014

Object Oriented Programming (oop)

The programming in which data is logically represented in the form of a class and physically represented in the form an object is called as object oriented programming (OOP).
There are some basic programming concepts in OOP:
  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphism

Abstraction

Abstraction is a process of hiding the implementation detail and only displaying the essential features. Abstraction is achieved by means of access specifies.
.Net has five access specifies
  • Public: Accessible outside the class through object reference.
  • Private: Accessible inside the class only through member functions.
  • Protected: Just like private but Accessible in derived classes also through member functions.
  • Internal:  Visible inside the assembly. Accessible through objects.
  • Protected Internal: Visible inside the assembly through objects and in derived classes outside the assembly through member functions.
In object-oriented software, complexity is managed by using abstraction.Abstraction is a process that involves identifying the critical behavior of an object and eliminating irrelevant and complex details.
Advantages of abstraction are the hiding of implementation details, component reuse, extensibility, and testability. When we hide implementation details, we reveal a cleaner, more comprehensible and usable interface to our users. We are separating our interface from our implementation, and this makes component reuse more practical. Many, if not all of the object-oriented concepts we have discussed throughout this document play a role in the abstraction principle. Working together, their end goal is the same, to produce software that is flexible, testable, maintainable, and extensible


What is Constructor in C# ?


In C#, Constructor is a special kind of a method. It is automatically called, when the object is created. Constructors do not return values and have the same name as the class.  
Constructors are responsible for object initialization and memory allocation of its class. There is always at least one constructor in every class. If you don't write a constructor in class, 
C# compiler will automatically provide one constructor for that class, called default (parameter less) constructor.

Types of Constructor

Generally, constructors are of three types. But C# doesn't support copy constructor.

  1. Default Constructor(Non-Parameterized constructor)
  2. Parameterized Constructor
  3. Copy Constructor
  4.  Static Constructor
  5.  Private Constructor

Default Constructor Example
Example:

Object Oriented Programming (oop)

The programming in which data is logically represented in the form of a class and physically represented in the form an object is called a...