Sign in to follow this  

Interfaces [SOLVED]

This topic is 4516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 ).


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this