how we can achive abstraction in our code

Posted by Packs under C# on 10/3/2012 | Points: 10 | Views : 3132 | Status : [Member] | Replies : 4
Hello

we can achieve
inheritance = base class ,child class
polymorphism = overloading, overriding
encapsulation = class
what about
abstraction= ?




Responses

Posted by: Pgayath on: 10/12/2012 [Member] Starter | Points: 25

Up
0
Down
hi,

Abstraction is the process of showcasing only the essential features, hiding the implementation details. It hides the complexity to the outer world.

Best example of abstraction is your Abstract Classes .

Thanks and Regards,
Gayathri P



Packs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
hi...

the term abstraction can simplify by the following cde:

class A

{
public void abc()
{
Console.Write("Hello");
}
}


The method "abc" of the above class will be called in the main function of the program class.


class program

{
public static void Main()
{
A obj=new A();
obj.abc();
Console.ReadKey();
}
}


So, in this way, it simply reduces the complexity and simplifies the program because class program does not have any concern with the methods or data members (variables) used in the class A but is to concern with abc method only. So, it hides the information too.

Sourabh07

Packs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Perumal93 on: 10/27/2012 [Member] Starter | Points: 25

Up
0
Down
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Abstract_Class
{
class Program
{
static void Main(string[] args)
{
A a = new A();

Console.WriteLine(a.display());
}
}

public abstract class AbstractClassDemo
{
public abstract string display();
}

public class A : AbstractClassDemo
{
public override string display()
{
return "This statement is written in abstract function display() of abstract class AbstractClassDemo";
}
}
}


Packs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dharanidhar on: 11/1/2012 [Member] Starter | Points: 25

Up
0
Down
Abstraction is the representation of only essential features of an object and hiding unessential features of an object.It is a oop mechanism that hides irrelevant data and shows only relevant data.
Abstract class is a class that has abstract methods as well as other normal methods and properties.Abstract class cant be instantiated but it can be inherited.
You can define abstract methods(that does'nt have any implementation) in the base class and later we can write the imlementation of these abstract methods in the derived class.Here we are showing the relevant or essential data in the base class.
Example
Base class:-
public abstract class ParentClass
{
public abstract int Add(int a, int b);
public abstract int Subtract(int a, int b);
}

Derived class:-
public class ChildClass
{
public override int Add(int a,int b)
{
return a+b;
}
public override int Substract(int a,int b)
{
return a-b;
}
}
In the Main class Write..
ChildClass c=new ChildClass();
Response.Write("The Sum:"+c.Sum(5,5));
Respnse.Write("The Substract:"+c.Substract(10,5));

Packs, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response