Java Interview Question
Use this advanced question and answer to prepare for your next Java interview.
Should you use external libraries in your code? What are the benefits and drawbacks? What precautions can be taken?
External libraries are extremely helpful when writing large and complex programs - they save the effort of having to code something which has already been implemented by someone else.
But this does not mean you should not use external libraries. There are some excellent ways to protect programs from being impacted very badly by such problems. One of the best ways to protect from external dependencies is to design that part of the code using Interfaces. Interfaces allow defining a contract or a specification that is binding on all implementers of the interface when implemented correctly. This frees the consumer to directly use the interface without having to care about the implementation.
If a bug is discovered in the implementation of a library, or the library gets deprecated, then it can be switched out for another library without having to modify the consumers of the interface. This type of design will make the whole program more robust.