Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!


+ Follow
since Sep 06, 2001
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by FullMoonParty

I'm glad someone else is having troubles with interfaces. I don't feel so bad now. There is NO other concept in Java that confuses me and frustrates me more than interfaces. I have read a number of articles and chapters in books on interfaces, and I am starting to believe I am just plain dense. I read them over and over and over and over and it still does not make sense.
Yet...I can articulate some (now) memorized facts regarding interfaces (ie. they are used to get around lack of support for multiple inheritance, they are similar to abstract classes except they provide no implementation at all, etc.)
I have not been able to find an example to make it stick. Right now the concept is very abstract (no pun intended). Most discussions on interfaces talk about the syntax. I got that part. I can define them. I can also implement them. What I can't do is tell a novice (my sister?) *why* I am going to use an interface (please do not say because I need multiple inheritance).
You guys have no idea how frustrating this is (or maybe you do). It's like dividing by zero--it doesn't compute. (for integers anyway). :-)
Let me *try* to describe why it eludes me...
An interface doesn't DO anything. (some of you may say that's the whole point). My rebelious mind says, why should I "implement" you when you dont DO anything for me? At least with an abstract class, I get SOME common functionality that is of use to me. All I get with an interface is a requirement that I implement some methods. I don't need an interface to tell me that I should implement some methods--I can do that on my own.
(I am not trying to be sarcastic or cynical--this is what my mind is thinking)
The example I always fall back on when thinking in OO is my college example years ago of an ATM application. This makes it easy to conceptualize abstract classes. Among other things, we had an abstract Account class with subclasses for Checking, Savings and CD. This is very tangible and real--we deal with this everyday in real life.
I then try to think, 'how would I put an interface to use in this context?'
It eludes me.
I keep reading and keep pursuing interfaces in the hopes that one day it 'clicks' and then it all makes sense. I'm planning on SCJP2 certification and I may get some/all questions on interfaces correct, because I understand (memorized?) the syntax/mechanics of declaring and using interfaces. But I don't know how to *design* using them.
Can anyone tell me how I might be able to use an interface in the ATM application example mentioned above? I desperately need to get past this mental block.
Alternatively, I used to program in VB--maybe an analogy to some concept there makes sense? I'm thinking they might be similar to the "handlers" that are available on UI widgets (ie. 'onClick, onChange, onExit'). The only problem is that these handlers exist whether or not use use them. If you decide to use them, you just pop some code in there. An interface on the other hand would require code in each of these (though a method definition and empty {} would suffice. Maybe this *is* an interface (in concept) and all the methods are predefined and a UI is available in VB to let the programmer stick in his/her code?
As you can see, I'm stretching for any analogy to make this concept click.