473,508 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interfaces???

Hi, can anyone have a go at explaining what an "Interface" is used for
and what exactly it is?

[attributes] [modifiers] interface identifier [:base-list]
{interface-body}[;]

MSDN is a little abstract for my level of knowledge.

Thanks!
Nov 15 '05 #1
3 1431
Adie <ar*******@h-o-t-m-a-i-l.com> wrote:
Hi, can anyone have a go at explaining what an "Interface" is used for
and what exactly it is?

[attributes] [modifiers] interface identifier [:base-list]
{interface-body}[;]

MSDN is a little abstract for my level of knowledge.


You were basically looking in the wrong section. Look under
"interfaces" in the index and there's a "tutorial" section which should
help you.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Adie,
Hi, can anyone have a go at explaining what an "Interface" is used for
and what exactly it is?


In OO-terminology we have stereotypes. A stereotype is an aspect of an
entity that is not necessarily related to its class. Let me give a
real-world example (well, sort of...). Say you have these classes in your
problem domain:

Dog, Plant, GirlFriend, Grandma, Car, Employer, Colleague.

Each may have its own inheritence root or some may share common roots like
Relative, Pet or PersonAtWork. Your class hierarchy may be quite complex and
will be based on some model that works for you when you want to make useful
software.

Now you may recognize some behavior you want to implement like receiving
money or paying. Being an OO-dude you would think up classes like Provider
and MoneySucker. Cool... But then what? If GirlFriend and Car are
MoneySuckers and Employer is a Provider, doesn't that conflic with the class
model you already have?

Provider and MoneySucker aren't really classes, they merely define behavior.
And you want to slap them on any class you find appropriate, independent of
their place in your class hierarchy. Provider and MoneySucker are
interfaces:

interface Provider
{
void PayMe();
void FeedMe();
}

interface MoneySucker()
{
void ShakeMeDown();
}

You can now implement these interfaces in any class you find appropriate.
The "contract" is defined once only. Since interfaces are types you may
iterate through all of your providers to collect money. When you need money
you don't really care about your objects being reletives, friends or
colleagues or whatever, while in the process of obtaining money you want to
treat them as providers.

Like you have your class tree, you may also have your interface tree.
Interfaces can inherit from base interfaces like classes. You will never
implement anything in an interface itself though, they merely define groups
of method signatures. If a class claims to implement an interface the
compiler will make sure that every method is indeed implemented and can be
called.

Cool huh?

Martin.
Nov 15 '05 #3
adie... an interface is a contract without implementation.
http://www.geocities.com/jeff_louie/OOP/oop9.htm

as an example, you can program to an interface and load a plug in class
at runtime that implements the interface
http://www.geocities.com/jeff_louie/OOP/oop13.htm

Regards,
Jeff
Hi, can anyone have a go at explaining what an "Interface" is used for

and what exactly it is?<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4

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

Similar topics

1
2184
by: baylor | last post by:
In C#, an interface cannot mark any method as static. i'm told the ILASM supports it but i've never tested that Two questions. First, why? OK, i've heard the reason about interfaces being...
30
2474
by: Frank Rizzo | last post by:
We are having one of those religious debates at work: Interfaces vs Classes. My take is that Classes give you more flexibility. You can enforce a contract on the descendant classes by marking...
8
1766
by: John | last post by:
What is the purpose / benefit of using an interface statement? It doesn't seem like anything more than a different way to make a class... (except you can't define any procedures in an interface...
9
5178
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
18
1963
by: _dee | last post by:
Question about best use of interfaces: Say there's a 'Master' class that needs to implement a few interfaces: class Master : I1, I2, I3 { } The actual code already exists in smaller...
22
2066
by: RSH | last post by:
Hi, I have been reading on interfaces working on samples I've run across on the web. For the life of me I cannot seem to grasp them. It appears to me that interfaces are simply blueprints to...
18
2371
by: Tony | last post by:
class Interface { public: virtual void DoItNow()=0; }; class A: public Interface { public: void DoItNow(); // satisfies interface explicitly
5
2992
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
10
1978
by: hyperboreean | last post by:
Hi, Probably it has been asked before, but I'll still ask. Why doesn't python provide interfaces trough its standard library? Or it was ever proposed to be included in the language? Zope's...
23
2184
by: A.Gallus | last post by:
If I declare a function pure virtual: class A { virtual void myfunc() = 0; } and I derive a class from A: class B : public A
0
7133
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...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7405
jinu1996
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...
0
5643
agi2029
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 project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.