File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Just JAVA book - Interface vs class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Just JAVA book - Interface vs class" Watch "Just JAVA book - Interface vs class" New topic
Author

Just JAVA book - Interface vs class

Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi, peter, when should we apply interface ? should it replace class ? thank you !
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
peter, do you mind to brief the chapter 11 - interface in your just JAVA book ? thank you !
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Alvin chew:
hi, peter, when should we apply interface ? should it replace class ? thank you !


We should apply interface, when we need multiple inheritance... They work differently from classes, so they should not replace class... Since Java does not allow multiple inheritance from classes, interfaces can mimic multiple inheritance...

Just my 2 cents..


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Chandra Sekhar
Ranch Hand

Joined: Sep 26, 2003
Posts: 90
Hi

When deciding to use interface,I think we should be correct at the first time.


If we need to add any methods to this interface in future it should be overridden in all classes implementing this interface,which can be over head.

I feel abstract class will be a suitable choice than interface in situations like this.

Chandrasekhar S


"Luck is when opportunity meets preparation"
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

This thread is also interesting
http://www.coderanch.com/t/99122/patterns/Should-there-ever-abstract-class


Groovy
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
First, you should be used Interface when you want create blueprint model of project. (Interface is like Abstract class But it's diferent.Interface VS Abstract Class)

Example in BookStore system you want to create MainSystem1, 2, 3, 4 all is business process for BookStore and each system can access to another system.

So

If you want to separate each system and hide implementation of each system, you should create Interface to define all method/behavior to access in each system.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Just JAVA book - Interface vs class