Oct 22, 2017, 11:41 AM

News:

Rajini Movie Latest Update Enthiran


oops & C#

Started by sukishan, Jul 11, 2009, 08:09 PM

previous topic - next topic
Go Down

sukishan

OOP & C#


   The skeleton of object - oriented programming is of course the concepts of class. This C# tutorial on OOPS explains classes and their importance in implementation of object ? oriented principles.

   Any language can be called object ? oriented if it has data and method that use data encapsulated in items named objects. An object ? oriented programming method has many advantages, some of them are flexibility and code reusability.

   All the programming languages supporting Object oriented Programming will be supporting these three main concepts:

Encapsulation
Inheritance
Polymorphism



Encapsulation in C#:
   Encapsulation is process of keeping data and methods together inside objects. In this way developer must define some methods of object?s interaction. In C# , encapsulation is realized through the classes. A Class can contain data structures and methods. Consider the following class.


--------------------------------------------------------------------------------

public class Aperture
{

public Aperture()
{

}

protected double height;
protected double width;
protected double thickness;

public double GetVolume()
{

double volume = height*width*thickness;
if(volume<0)
return 0;
return volume;

}

}


--------------------------------------------------------------------------------

   In this example we encapsulate some data such as height, width, thickness and method GetVolume. Other methods or objects can interact with this object through methods that have public access modifier. It must be done using ?.? operator.



Inheritance in C#:
   

In a few words, Inheritance is the process of creation new classes from already existing classes. The inheritance feature allows us to reuse some parts of code. So, now we have some derived class that inherits base class?s members. Consider the following code snippet:


--------------------------------------------------------------------------------

public class Door : Aperture
{

public Door() : base()
{

}

public bool isOutside = true;

}


--------------------------------------------------------------------------------

   As you see to inherit one class from another, we need to write base class name after ?:? symbol. Next thing that was done in code Door () ? constructor also inherits base class constructor. And at last we add new private field. All members of Aperture class are also in Door class. We can inherit all the members that has access modifier higher than protected.

Polymorphism in C#:
   Polymorphism is possibility to change behavior with objects depending of object?s data type. In C# polymorphism realizes through the using of keyword virtual and override. Let look on the example of code:


--------------------------------------------------------------------------------

public virtual void Out()
{
   Console.WriteLine("Aperture virtual method called");
}
//This method is defined in Aperture class.
public override void Out()
{
   Console.WriteLine("Door virtual method called");
}


--------------------------------------------------------------------------------


   Now we need to re-define it in our derived Door class. The usage of virtual methods can be clarified when we creating an instance of derived class from the base class:

Aperture ap = new Door();
ap.Out();

   In such cases, the runtime keeps record of all the virtual function details in a table called VMT(Virtual Method Table) and then in runtime dynamically picks the correct version of the function to be used. Here it uses Out() method from derived class of course.
A good beginning makes a good ending

pradeep prem

this should be define in the object oriented programming
the inheritance programalso given in c

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:
Verification:
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview
IT Acumens | GinGly :: SMS Backup | Acumen :: Discussion Board | AshokPillar :: Hosting | CineBuzz :: Latest Cinema News | My Kids Diary :: Capture your kids magical moment
Copyright 2005 - 2017 :: IT Acumens :: All Rights Reserved.
ITAcumens Forum with 2 lakhs post running for 10 years - Powered by HostGator Dedicated Server