473,385 Members | 1,506 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,385 software developers and data experts.

Interface vs. Abstract class

Moving from C++ to C# .Net:

Why does an interface exist in C# when I can create one by making all methods in
the abstract class "pure virtual"?
Did I miss something conceptually or is the "interface" just here for my
conveniance?
If it is a convinient thing, what style is accepted by the C# community (or mcsd
requirements) as the standard?
Jul 23 '06 #1
3 5364
"Valmont" <ax***********@hotmail.comwrote:
Moving from C++ to C# .Net:

Why does an interface exist in C# when I can create one by making
all methods in the abstract class "pure virtual"?
Because .NET doesn't support multiple inheritance.
Did I miss something conceptually or is the "interface" just here for my
conveniance?
If it is a convinient thing, what style is accepted by the C# community (or mcsd
requirements) as the standard?
Interfaces are also useful in their own right, since the notion of a
stateless "supports" relationship is distinct from a class-based "is-a"
relationship.

Interfaces also have downsides that make abstract base classes
preferable in many situations - I made a post in this group a few days
ago in response to Jon Skeet listing some of them.

-- Barry

--
http://barrkel.blogspot.com/
Jul 23 '06 #2

"Barry Kelly" <ba***********@gmail.comschreef in bericht
news:65********************************@4ax.com...
| "Valmont" <ax***********@hotmail.comwrote:
|
| Moving from C++ to C# .Net:
| >
| Why does an interface exist in C# when I can create one by making
| all methods in the abstract class "pure virtual"?
|
| Because .NET doesn't support multiple inheritance.

| Interfaces are also useful in their own right, since the notion of a
| stateless "supports" relationship is distinct from a class-based "is-a"
| relationship.
|| -- Barry
|
| --
| http://barrkel.blogspot.com/
Oh I see now. Thank you for your very fast response.
Jul 23 '06 #3
Valmont wrote:
Moving from C++ to C# .Net:

Why does an interface exist in C# when I can create one by making all methods in
the abstract class "pure virtual"?
Did I miss something conceptually or is the "interface" just here for my
conveniance?
You cannot inherit from multiple classes in C#, but
you can implement multiple interfaces.
Jul 23 '06 #4

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
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
9
by: phl | last post by:
hi, I am kind of confused aobut interfaces and abstract classes. In short as I understand it, an interface is like a contract between the class and the interface, so that certain funtions must...
10
by: Brett | last post by:
I'm still trying to figure out concrete reasons to use one over the other. I understand the abstract class can have implementation in its methods and derived classes can only inherit one abstract...
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...
18
by: Bradley | last post by:
I'm trying to determine if there's a general rule for when an Interface should used vs. an Abstract Class. Is there any design advantage to using one or the other? Brad
5
by: Tony Johansson | last post by:
Hello!! Assume you have an Interface called ITest with these three method declarations. interface ITest { void foo1(); void foo2(); void foo3(); }
7
by: gordon | last post by:
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...
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...
7
by: tshad | last post by:
I am trying to understand Interfaces and why I would use them. I have an example from a book that is explaining it. I just can't seem to see why I would use it. In my example, it has 2...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.