What is Abstract and interface

Posted by Jayakumars under ASP.NET AJAX on 9/5/2013 | Points: 10 | Views : 1014 | Status : [Member] [MVP] | Replies : 5
Hi

I have created Webapplication Project how to implemented Abstract and interface
then what is the use of both class then also how to override this class

can you explain with source code plz any one post source code

Mark as Answer if its helpful to you


Responses

Posted by: Bandi on: 9/6/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
//Interface definition

public interface IFoo
{
void Method1();
void Method2();
}

// Abstract class derived from above Interface... Here we should provide implementation for all methods/classes that are in interface
public abstract class BaseClass : IFoo
{
public void Method1()
{
// Common stuff for all BaseClassX classes
}

// Abstract method: it ensures IFoo is fully implemented
// by all classes that inherit from BaseClass, but doesn't provide
// any implementation right here.
public abstract void Method2();
}

//observe the following two classes MyClass1 & MyClass2.. Same method "Method2()" have two different implementation parts as per class
// By using override it is possible..... Main advantage of Interface is that it provides only the method/class declarations & constants and then different vendors can implement their own functionality by following common structure/signature
public class MyClass1 : BaseClass
{
public override void Method2()
{
// Specific stuff for MyClass1
Console.WriteLine("Class1");
}
}

public class MyClass2 : BaseClass
{
public override void Method2()
{
// Specific stuff for MyClass2
Console.WriteLine("Class2");
}
}

private static void Main(string[] args)
{
IFoo test1 = new MyClass1();
IFoo test2 = new MyClass2();

test1.Method2();
test2.Method2();

Console.ReadKey();
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Bandi on: 9/6/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Interfaces:
http://www.blackwasp.co.uk/Interfaces.aspx
Abstract Classes:
http://www.blackwasp.co.uk/AbstractClasses.aspx
http://www.blackwasp.co.uk/ForcedOverride.aspx

Sample: http://stackoverflow.com/questions/13442312/when-do-i-use-abstract-class-or-interface-in-dependency-injection

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Jayakumars on: 9/6/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

how to implemented in my Asp.net C# web project can you post them.

Mark as Answer if its helpful to you

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

Posted by: Bandi on: 9/6/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi Jayakumar,
Look into the following links... One link is for how interfaces & Abstract classes are used in ecommerce/bigbazzar type applications....
http://stackoverflow.com/questions/10535040/use-of-interface-and-abstract-class-for-specific-to-my-application
http://forums.asp.net/t/1474366.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Vamc on: 7/1/2014 [Member] Starter | Points: 25

Up
0
Down
Go to the below link to find Detail explanation on Abstraction and Interface

http://www.dotnetchallengers.com/App_Folder/Content/Tutorials/abstraction/Abstraction.aspx
http://www.dotnetchallengers.com/App_Folder/Content/Tutorials/Interface/Interface.aspx

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

Login to post response