Aren't all classes interfaces?
What constitutes an interface (and with it, the "I" prefix
distinction)?
Zytan 17 2248
Hi,
"Zytan" <zy**********@yahoo.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
Aren't all classes interfaces?
All classes define (at least) one interface. But they are not the same.
What constitutes an interface (and with it, the "I" prefix
distinction)?
An interface is a contract. It means that any class that implement it has to
implement all the members declared in it.
Take a look at MSDN for a better more in depht explanation
Aren't all classes interfaces?
>
All classes define (at least) one interface. But they are not the same.
You mean, the word 'interface' has two meanings?
What constitutes an interface (and with it, the "I" prefix
distinction)?
An interface is a contract. It means that any class that implement it has to
implement all the members declared in it.
Unfortunately, knowing nothing about it, I don't follow this at all.
Are you talking about inheritance?
Take a look at MSDN for a better more in depht explanation
I tried, but there are so many interfaces in MSDN, it's hard to find a
simple explanation. I guess I'll have to dig in and read about one in
general. I find MSDN (mostly) very useless except as a reference.
That is, it doesn't help someone unless they sort of already know.
This was a particular known problem the help guys were supposed to fix
for v2005.
Zytan
On 28 Feb 2007 13:35:34 -0800, "Zytan" <zy**********@yahoo.comwrote:
>Aren't all classes interfaces?
What constitutes an interface (and with it, the "I" prefix distinction)?
Zytan
An interface is a class (or struct). It contains methods, properties,
indexers or events. It does not provide implementations for any of
its methods.
The advantage of an interface is that any other class (or interface)
can "inherit" (or implement) that interface. It is the C# way to get
something similar to multiple inheritance in C++. Any class that
implements an interface must supply all the members specified in the
interface.
rossum
An interface is a class (or struct). It contains methods, properties,
indexers or events. It does not provide implementations for any of
its methods.
The advantage of an interface is that any other class (or interface)
can "inherit" (or implement) that interface. It is the C# way to get
something similar to multiple inheritance in C++. Any class that
implements an interface must supply all the members specified in the
interface.
Thanks, rossum, this explains a lot.
But, I need to be more experience before I can understand why an
interface is needed. I never used multiple inheritence before.
Zytan
On Feb 28, 5:13 pm, "Zytan" <zytanlith...@yahoo.comwrote:
An interface is a class (or struct). It contains methods, properties,
indexers or events. It does not provide implementations for any of
its methods.
The advantage of an interface is that any other class (or interface)
can "inherit" (or implement) that interface. It is the C# way to get
something similar to multiple inheritance in C++. Any class that
implements an interface must supply all the members specified in the
interface.
Thanks, rossum, this explains a lot.
But, I need to be more experience before I can understand why an
interface is needed. I never used multiple inheritence before.
Check out these threads: http://groups.google.com/group/micro...0909d1382f3e68 http://groups.google.com/group/micro...667cc111cc960b
rossum <ro******@coldmail.comwrote:
An interface is a class (or struct). It contains methods, properties,
indexers or events. It does not provide implementations for any of
its methods.
I think it's misleading to say that an interface is a class or a
struct. An interface is a distinct kind of type in itself. It may be
*implemented* by a class or a struct, but in itself, it is neither.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Zytan <zy**********@yahoo.comwrote:
But, I need to be more experience before I can understand why an
interface is needed. I never used multiple inheritence before.
There's much more to interfaces than providing a workaround for the
lack of multiple inheritance. It allows you to use a class knowing only
that it implements the interface. Probably the most commonly used
interface in .NET is IDisposable, which defines the Dispose method.
That means that I could have a method:
void DisposeOfSomething (IDisposable x)
{
x.Dispose();
}
and *anything* implementing IDisposable could be passed to the method.
It's a way of providing polymorphism which is independent of the class
hierarchy (i.e. there's no particular base class needed).
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
On Thu, 1 Mar 2007 07:37:45 -0000, Jon Skeet [C# MVP]
<sk***@pobox.comwrote:
>There's much more to interfaces than providing a workaround for the lack of multiple inheritance. It allows you to use a class knowing only that it implements the interface.
Well yes, but the same is true if you use a class knowing only that it
implements a given base class...
>It's a way of providing polymorphism which is independent of the class hierarchy (i.e. there's no particular base class needed).
That's only true because .NET doesn't support multiple inheritance in
the first place. Otherwise you could attach some new base class at an
arbitrary point in any class hierarchy, in the same way as you can now
attach an arbitrary interface. You would no longer consider that
particular base class part of a "hierarchy" either.
-- http://www.kynosarges.de
Chris Nahr <di******@kynosarges.dewrote:
There's much more to interfaces than providing a workaround for the
lack of multiple inheritance. It allows you to use a class knowing only
that it implements the interface.
Well yes, but the same is true if you use a class knowing only that it
implements a given base class...
True.
It's a way of providing polymorphism which is independent of the class
hierarchy (i.e. there's no particular base class needed).
That's only true because .NET doesn't support multiple inheritance in
the first place. Otherwise you could attach some new base class at an
arbitrary point in any class hierarchy, in the same way as you can now
attach an arbitrary interface. You would no longer consider that
particular base class part of a "hierarchy" either.
I would - if a class has two base classes, I'd count both of those as
being in the class hierarchy for that class.
I suppose using interfaces is equivalent to using multiple inheritance
where you can only inherit from one class with any concrete methods. As
I understand it, however, multiple inheritance is usually used to
inherit implementation, not interface. I could be wrong there, of
course.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Check out these threads:
> http://groups.google.com/group/micro...languages.csha...
http://groups.google.com/group/micro...languages.csha...
Thanks, these help a lot.
You could have implementations that are totally different, say, SQL
data, or flat file (text file) data, or XMl data, and have an
interface that is the same for all of them. And the implementations
of these would use the same interface. The interface *forces* that
all of it is implemented (very good c#) which forces that it is done
correctly. Impressive concept.
Zytan
An interface is a class (or struct). It contains methods, properties,
indexers or events. It does not provide implementations for any of
its methods.
I think it's misleading to say that an interface is a class or a
struct. An interface is a distinct kind of type in itself. It may be
*implemented* by a class or a struct, but in itself, it is neither.
I understand it now. A C# interface (the keyword interface) which
should have the "I" prefix is not the interface portion of a class.
They are both interfaces just as pointers and references are both
references (in plain english). But I understand the distinction now.
IClass means that it is an 'interface' not a 'class'.
Zytan
There's much more to interfaces than providing a workaround for the
lack of multiple inheritance. It allows you to use a class knowing only
that it implements the interface. Probably the most commonly used
interface in .NET is IDisposable, which defines the Dispose method.
That means that I could have a method:
void DisposeOfSomething (IDisposable x)
{
x.Dispose();
}
and *anything* implementing IDisposable could be passed to the method.
It's a way of providing polymorphism which is independent of the class
hierarchy (i.e. there's no particular base class needed).
I have no experience with polymorphism so this is over my head, but I
think I understand. I want two totally different implementations that
show the same interface to the caller. This way, the called need not
care about the internal code, it just uses it, much like, say,
electric motors vs gas motors work under the hood, but have the same
steering wheel and 'gas' pedal to make it move. So, this concept,
which I understand, is basically what polymorphism is, isn't it?
Zytan
On Mar 1, 8:56 am, "Zytan" <zytanlith...@yahoo.comwrote:
Check out these threads:
http://groups.google.com/group/micro...languages.csha...
http://groups.google.com/group/micro...languages.csha...
Thanks, these help a lot.
You could have implementations that are totally different, say, SQL
data, or flat file (text file) data, or XMl data, and have an
interface that is the same for all of them. And the implementations
of these would use the same interface. The interface *forces* that
all of it is implemented (very good c#) which forces that it is done
correctly. Impressive concept.
Zytan
Yes, interface to me is more useful as design mechanism. Look up
Design Patterns.
Quoc Linh
On Mar 1, 10:59 am, "Zytan" <zytanlith...@yahoo.comwrote:
An interface is a class (or struct). It contains methods, properties,
indexers or events. It does not provide implementations for any of
its methods.
I think it's misleading to say that an interface is a class or a
struct. An interface is a distinct kind of type in itself. It may be
*implemented* by a class or a struct, but in itself, it is neither.
I understand it now. A C# interface (the keyword interface) which
should have the "I" prefix is not the interface portion of a class.
They are both interfaces just as pointers and references are both
references (in plain english). But I understand the distinction now.
IClass means that it is an 'interface' not a 'class'.
Zytan
The naming of an interface is irrelevant. You could name it TimBukToo
for all the compiler cares. Prefixing an interface type name with the
letter I is just a best practice. It is not required.
Zytan <zy**********@yahoo.comwrote:
It's a way of providing polymorphism which is independent of the class
hierarchy (i.e. there's no particular base class needed).
I have no experience with polymorphism so this is over my head, but I
think I understand. I want two totally different implementations that
show the same interface to the caller. This way, the called need not
care about the internal code, it just uses it, much like, say,
electric motors vs gas motors work under the hood, but have the same
steering wheel and 'gas' pedal to make it move. So, this concept,
which I understand, is basically what polymorphism is, isn't it?
Yes, that's a pretty reasonable way of looking at it.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
rossum <ro******@coldmail.comwrote:
>An interface is a class (or struct). It contains methods, properties, indexers or events. It does not provide implementations for any of its methods.
I think it's misleading to say that an interface is a class or a
struct. An interface is a distinct kind of type in itself. It may be
*implemented* by a class or a struct, but in itself, it is neither.
There is a difference between an interface as a .Net construct and interface
as the way in which we interact with an object. You could sat that a class
is it's own interface.
PS
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
PS <ec***********@hotmail.comwrote:
I think it's misleading to say that an interface is a class or a
struct. An interface is a distinct kind of type in itself. It may be
*implemented* by a class or a struct, but in itself, it is neither.
There is a difference between an interface as a .Net construct and interface
as the way in which we interact with an object.
Yes - but in the context of someone in a C# group asking what an
interface, I think it's clear what's meant.
You could sat that a class is it's own interface.
Well, I'd say that a class *has* its own public interface (which it
implements), but it *isn't* its own interface.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
by: zlst |
last post by:
Many technological innovations rely upon User Interface Design to elevate
their technical complexity to a usable product. Technology alone may not win
user acceptance and subsequent marketability....
|
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...
|
by: YellowFin Announcements |
last post by:
Introduction
Usability and relevance have been identified as the major factors
preventing mass adoption of
Business Intelligence applications. What we have today are traditional
BI tools that...
|
by: Xah Lee |
last post by:
On Java's Interface
Xah Lee, 20050223
In Java the language, there's this a keyword “interface”.
In a functional language, a function can be specified by its name and
parameter specs....
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
| |