Interfaces [SOLVED]

Started by
10 comments, last by Thaligar 18 years, 8 months ago
Hi folks, ok, i surfed now for a couple of hours to find a good example of "how does an inteface look like" and "how can i use it", probably i'm to dump to find this stuff, but all i can get is a short overview and then most of the articles goes futher to singletons (probably a natural phenomenom), if anybody knows a page or an article i can absorp please post, thx in advance for your time, greets tgar [Edited by - Thaligar on August 4, 2005 9:50:47 AM]
Advertisement
What context do you mean "interface"? Interface can mean many different things, from the public parts of a class, the graphical user interface in a windowing library, to the meeting of two surfaces. As in try giving a complete sentence that uses the word interface that you are having trouble understanding.
Depending on what language you're using, an interface is usually a abstract class. You can't instanciate it and you usually use it to force features into a class.

For instance, in C#, there is an IDisposable interface. If your class uses unmanaged resources, you need to get rid of those. So you let the class implement the IDisposable interface, and thus you're forced to write a Dispose function.

Same goes with Java and events. Buttons require an ActionListener. So if your class must handle button events, you declare your class as:

public class ButtonEventHandler implements ActionListener{    public void ActionPerformed(ActionEvent e)    {    }}


The ActionListener interface forces you to write the ActionPerformed function.

So. interfaces are used to force specific behaviour into a class.

Toolmaker

If we talk about object oriented programming an interface is

Quote:
a device or a system that unrelated entities use to interact. According to this definition, a remote control is an interface between you and a television set, the English language is an interface between two people, and the protocol of behavior enforced in the military is the interface between people of different ranks.
(from the Java tutorial)


Read more here (at java.sun.com): What Is an Interface?.

(although the above link is Java specific is useful info none the less).
"We confess our little faults to persuade people that we have no large ones." -Francois de La Rochefoucauld (1613 - 1680). | My blog
Sorry, my fault,

Language: C++

meaning: Interface class

like:

CRenderer -> IRenderer -> Application

so that i can change the whole renderer without changing the interface, like switching between directX and OpenGL

thx,

greets
tgar
Then you want an pure abstract base class.

That is a class which contains no member variables and all functions are declared virtual and are abstract ( =0 ).


thanks,

that's what i want,
that's a good start,

now i'm going to look for virtual functions...

thx again to all for your time,
greets
tgar

well, i read yesterday a lot about virtual functions as well as about pure v. func.,

so, after the declaration of my completly abstract class
i have to derive another class from my abstract one,
override the virtual functions

and finally i can use different classes with the same interface
(right??)

so it's really important that the interface should be as good as possible, right?

thx & greets
tgar
A good start is looking at how COM objects are created since they are all interfaces. here is a good start to learning about COM objects, or if that isn't what you are looking for, you can always try this google search.


~guyaton
~guyaton
Quote:Original post by Thaligar
so it's really important that the interface should be as good as possible, right?


it's the most important part, everything else can change but once you've published and commited to an interface changing it becomes very hard.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats

This topic is closed to new replies.

Advertisement