dcsimg
Difference between abstract class and interface
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dibyendu_Das
Posted On:   Monday, September 8, 2003 12:20 PM

what is the difference between abstract class and interface and why do we need interface?

Re: Difference between abstract class and interface

Posted By:   Anonymous  
Posted On:   Monday, October 13, 2003 07:32 PM

an interface is a device that unrelated objects use to interact with each other.

The bicycle class (abstract class) and its class hierarchy (mountainBike, racingBike subclasses of bycycle) defines what a bicycle can and cannot do in terms of its "bicycleness." But bicycles interact with the world on other terms. For example, a bicycle in a store could be managed by an inventory program. An inventory program doesn't care what class of items it manages as long as each item provides certain information, such as price and tracking number. Instead of forcing class relationships on otherwise unrelated items, the inventory program sets up a protocol of communication. This protocol comes in the form of a set of constant and method definitions contained within an interface. The inventory interface would define, but not implement, methods that set and get the retail price, assign a tracking number, and so on.

interface --

Captures similarities among unrelated classes without artificially forcing a class relationship.

Declaring methods that one or more classes are expected to implement.

Revealing an object's programming interface without revealing its class

Re: Difference between abstract class and interface

Posted By:   Amir_Pashazadeh  
Posted On:   Monday, September 8, 2003 03:14 PM

Hi



Many differences, I will explain some more:


  • Java (and many other languages) doesn't support multiple inheritence. Multiple inheritence can cause many difficulties in application development, and maintenance.

  • Interfaces are PURE ABSTRACT but abstract classes can have some sort of implementation, and some implemented parts.

  • I believe interfaces are best for interfacing a package, application, sub system, etc. to other codes. For example JDBC standard interfaces (in java.sql and javax.sql packages) are just for interfacing applications with this kind of libraries, and the client would not be hardly coupled with a special implementation.


Amir Pashazadeh

About | Sitemap | Contact