This concept is unclear with me.
I have worked on several frameworks for an instance Spring. To implement a feature we always implement some interfaces provided by the framework.
For an instance if I have to create a custom scope in Spring, my class implements a org.springframework.beans.factory.config.Scope interface. Which has some predefined low level functionality which helps in defining a custom scope for a bean.
Whereas in Java I read an interface is just a declaration which classes can implement & define their own functionality. The methods of an interface have no predefined functionality.
interface Car
{
topSpeed();
acclerate();
deaccelrate();
}
The methods here don't have any functionality. They are just declared.
Can anyone explain this discrepancy in the concept? How does the framework put some predefined functionality with interface methods?
How does the framework put some predefined functionality with interface methods?
-- By providing an implementation for that interface, just like you do when you write a class that inherits the interface. – Robert Harvey Jan 27 '14 at 17:10Mercedes
can only extendCar
, cannot extendLuxuryVehicle
. However,Mercedes
can implement multiple interfaces. Google on "diamond inheritance problem", "multiple inheritance" and "favor composition over inheritance". Java 8 has a sort of multiple inheritance, I think, making it more like C++ in terms of diamond inheritance problem... – Thufir Mar 13 at 13:39