In interface based programming clients communicate with objects exclusively through interface references. This ensures that clients never build dependencies on the classes that serve up objects. This allows programmers to revise their object code without worrying about breaking client code. Clients can get run-time type information from objects. A client can always query an object and ask if it supports a specific interface. If the requested interface is not supported, the client can discover this and degrade gracefully. This lets programmers revise components and applications independently.
Joined: Oct 13, 2010
Thanks for the info
Mr sujeet khandelwal
Joined: Dec 21, 2011
For your question "What was the advantage of invoking the method through interface instance rather than class instance?"
See there are 3 things... Business Interface, Business class which implements Business Interface and Client code.
- In interface based programming... advantage is Client code is not changed whenever we change code of business class (business logic)...
Once interface is created it is just used for implementation and it is never changed.
Client uses only interface to access EJB's method so client code is also never changed as interface is never changed.
Now class which implements Business interface, business logic can be changed in this class and that will not impact client code as we are can not change method definition.
- Now consider the case where only 2 things we have Business class and client code...
Client uses business class to access methods.
As Business class developer is not aware of client code and while doing changes in business logic if he makes any changes in business method's definition that will surely harm the client code.