473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

diff between abstract class and interface

Hi

I am working through some course notes for a msdn training course in C# and
I am a little stuck with the differences between an abstract class and an
interface.

Could someone please give me a short understanding of what the differences
are?

I understand that the abstract class, if called must have its methods and
members included in the derived class - but it appears that is the same for
the interface.

Any links to information about the differences would be useful to.

Thanks in advance

doug
Sep 14 '06 #1
7 1644
gordon wrote:
Hi

I am working through some course notes for a msdn training course in C# and
I am a little stuck with the differences between an abstract class and an
interface.

Could someone please give me a short understanding of what the differences
are?

I understand that the abstract class, if called must have its methods and
members included in the derived class - but it appears that is the same for
the interface.

Any links to information about the differences would be useful to.

Thanks in advance

doug

I am sure you can google a lot of answers to this question. But one
quick notes is that:

you can ONLY inherit from one abstract class, but you can implement a
lot of interfaces.
Sep 14 '06 #2
"gordon" <go**********@optusnet.com.auwrote in message
news:45***********************@news.optusnet.com.a u...
Hi

I am working through some course notes for a msdn training course in C#
and I am a little stuck with the differences between an abstract class and
an interface.

Could someone please give me a short understanding of what the differences
are?

I understand that the abstract class, if called must have its methods and
members included in the derived class - but it appears that is the same
for the interface.

Any links to information about the differences would be useful to.
An abstract class can contain code, an interface cannot.
A class can implement many interfaces but can only be inherited from one
class.
An abstract class can have protected members.

Michael
Sep 14 '06 #3
I would add, correct me if I'm wrong, that an abscract class could have
static methods while the interface cannot...

gordon a écrit :
Hi

I am working through some course notes for a msdn training course in C# and
I am a little stuck with the differences between an abstract class and an
interface.

Could someone please give me a short understanding of what the differences
are?

I understand that the abstract class, if called must have its methods and
members included in the derived class - but it appears that is the same for
the interface.

Any links to information about the differences would be useful to.

Thanks in advance

doug
Sep 14 '06 #4
Hi Gordon,

gordon napisa³(a):
Hi

I am working through some course notes for a msdn training course in C# and
I am a little stuck with the differences between an abstract class and an
interface.

Could someone please give me a short understanding of what the differences
are?

I understand that the abstract class, if called must have its methods and
members included in the derived class - but it appears that is the same for
the interface.

Any links to information about the differences would be useful to.

Thanks in advance

doug
There is a lot of knowledge on this newsgroup that you can
acquire.

In short:

An *interface* is a contract, that should be provided in the
class (or structure) that implements it.

An *abstract_class* is a class that can not be instantiated
directly, because it contains the *abstract* members (methods
or properties).

The usually, way of class design look like this:

1. define an interface, e.g.:
public interface IMyInterface
{
}

2. implement an abstract class, e.g.:
public abstract class MyClassBase: IMyInterface
{
}

3. implement a class, e.g.:
public class MyClass: MyClassBase
{
}

The power of abstract class is:

1. You can force its constuctor parameters, e.g.:
protected MyClassBase(int myFirstParam, string mySecondParam) {
}

2. You can provide a way of code execution, e.g.

// in MyClassBase
protected abstract int Execute(string firstParam);

public int Execute() {
return this.Execute("My string");
}

// so you'll have to provice in MyClass
protected override int Execute(string firstParam) {
return "My result";
}

with regards
Marcin
Sep 14 '06 #5
Read there http://www.codeproject.com/csharp/ab...interfaces.asp

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"gordon" wrote:
Hi

I am working through some course notes for a msdn training course in C# and
I am a little stuck with the differences between an abstract class and an
interface.

Could someone please give me a short understanding of what the differences
are?

I understand that the abstract class, if called must have its methods and
members included in the derived class - but it appears that is the same for
the interface.

Any links to information about the differences would be useful to.

Thanks in advance

doug
Sep 14 '06 #6
Actually in IL you can have static methods on either .. no high level
language that I know of supports this but the CLR does (static methods are
simply bound to a type)

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

<ba******@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
I would add, correct me if I'm wrong, that an abscract class could have
static methods while the interface cannot...

gordon a écrit :
Hi

I am working through some course notes for a msdn training course in C#
and
I am a little stuck with the differences between an abstract class and an
interface.

Could someone please give me a short understanding of what the differences
are?

I understand that the abstract class, if called must have its methods and
members included in the derived class - but it appears that is the same
for
the interface.

Any links to information about the differences would be useful to.

Thanks in advance

doug

Sep 14 '06 #7
Following are the significant differences between an abstract class and an
interface:

1. In an abstract class some of the methods may be defined and some of them
may be abstract. In case of an Interface, none of the methods can be defined.

2. In an interface all the members must be public. In an abstract class this
is not the limitation.

3. A class can inherit from one abstract class but a class can implement
many interfaces.

--
Nand Kishore Gupta
"gordon" wrote:
Hi

I am working through some course notes for a msdn training course in C# and
I am a little stuck with the differences between an abstract class and an
interface.

Could someone please give me a short understanding of what the differences
are?

I understand that the abstract class, if called must have its methods and
members included in the derived class - but it appears that is the same for
the interface.

Any links to information about the differences would be useful to.

Thanks in advance

doug
Sep 15 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
10
by: Joe | last post by:
My question is more an OOD question. I know *how* to implement both abstract classes and interfaces. Here's my question - under what circumstacnes does one use an abstract class and under what...
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
3
by: chandu | last post by:
hello, what is the difference to use the keyword virtual,abstract when we are overriding the methods.instead of abstract shall we use virtual everywhere when we need to override? i am little...
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
4
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
6
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it...
2
by: pinki panda | last post by:
i want to knw the diff between static class and abstract class .i would appreciate if its followed by example
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.