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