What is Inversion Of Control (IOC)?

Inversion Of Control is a design pattern which suggests the creation of collaborating objects and injecting them should not be done by the dependent object itself. For example, Suppose WhetherController(Servlet) is depend on WhetherService which is depend WhetherDAO. WhetherController .javaclass WhetherController extends HttpServlet{ protected doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { WhetherService service = new WhetherService(); service.doSomething(params);….…. }} WhetherService.javaclass WhetherService{ public void doSomething(Map params) { WhetherDAO dao = new WhetherDAO();dao.getWhetherReport(); }} WhetherDAO.javaclass WhetherDAO{ // code to interact with Database} If you code as said above and if it is a big project you may use WhetherService/WhetherDAO in several classes.

Continue reading »