Solved

Interfaces. What, Why, Where?

Posted on 2001-09-14
6
216 Views
Last Modified: 2010-03-31
Hi,

I have been coding in Java for a while now, but I am interested why Interface classes are used? Could you name an example of using Interfaces.  This is NOT  school project, but every project that I have programmed, I have never created an Interface class.  I am just wondering if it is either my poor identification of classes or that I don't actually need to use them!

Thanks in advance.

Regards,

David.
0
Comment
Question by:david_d
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6484165
But you've used them so that should give you some understanding of there use.
One their main strength is that they allow you to seperate function, from implementation. The interface defines the function or contract but leaves the details of how it is actually implemented to the implementing class. Allowing you to potentially use different implementations without impacting on your application.

They also provide a means to implement multiple inheritance (try implementing multiple inheritance without using interfaces).

0
 
LVL 3

Expert Comment

by:black
ID: 6484180
0
 

Expert Comment

by:inmomi
ID: 6484595
Hi David,

   This explanation may be useful. Interfaces can be used to abstract ur implementation from outside world. They are powerful when u start working on distributed computing technologies like RMI and EJB where ur business logic is hidden from the client side who gets a home object or remote object and makes method calls to get the functionality done.

Regards

Inmomi
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 4

Accepted Solution

by:
k.jones earned 80 total points
ID: 6485177
interfaces -- when to use

There are two important differences between interfaces and abstract classes.

1. Interfaces provide a form of multiple inheritance, because you can implement multiple interfaces.  A class can extend only one other class, even if that class has only abstract methods.

2. An abstract class can have a partial implmentation, protected parts, static methods, and so on, whereas interfaces are limited to public constants and methods with no implementation.

These differences usually direct the choice of which is best to use in a particular implementation.  If multiple inheritance is important or even useful, interfaces are used.

Any major class you expect to be extended, whether abstract or not, should be an implementation of an iterface.  Although this approach requires a little more work on your part, it enables a whole category of use that is otherwise precluded.  For example, suppose we had created an Attributed class instead of an Attributed interface with an AttributedImpl implementation class.  Programmers who wanted to create new classes that extended other existing classes could never use Attributed, since you can extend only one class.  Because Attributed is an interface, programmers have a choice: they can extend AttributedImpl directly and avoid forwarding, or, if they cannot extend, they can at least use forwarding to implement the interface.  You can even provide multiple possible implementations of the interface to prospective users.

Cheers,
Ken Jones
0
 
LVL 1

Author Comment

by:david_d
ID: 6485520
I am sorry, but your proposed answer is does not explain what I am looking for.  It does not describe in enough detail about Interfaces.

The comment k.jones has provided, describes Interfaces in a clear and understandable manner.

Sorry.

David.
0
 
LVL 1

Author Comment

by:david_d
ID: 6485522
Thank you for your well descriptive comment/answer.

Thanks.

David.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven disable workspace resolution 1 77
Is there a simpler dropbox system? 10 53
hashmap order 17 62
jsp CRUD operations with and without prepared statement also hibernatge 1 50
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question