This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, In one of the interviews i attended i was asked the following question:
" Abstract classes are more faster than Interfaces in implementation, then y do we go for interfaces over an abstarct class, and y in Java we find many interfaces? as almost everything is an interface."
what is the exact answer for this? My answers didn't satisfy them.
I doubt that there is an "exact answer". However, this topic has been discussed on several occassion here at the Saloon. You should use the Search tool to find these threads. Using something like "interface abstract class" as the search keywords should turn up some decent results.
As for why we find so many interfaces ... Many design patterns and object oriented principles are focused on reducing dependency between classes, packages and larger grained components. They try to isolate sites of change - if this class changes often keep it away from classes that never change so we can avoid breaking the stable class and better organize our testing - and make change possible - I can introduce a new widget without modifying the thing that uses widgets. It's a fascinating area of study that repidly takes you into fairly advanced territory!
Google for "patterns in Java" to see some examples. HERE is something I put together for my team that shows some examples, too.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi