I need to implement servlet 3.0 webapp without dependency injection framework. Which solution is the best practice ? (in terms of performance/memory usage and scalability)
1) static methods for DAO and service layer
@WebServlet("/welcome")
public class MyController extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
MyService.doSomething(/*args*/);
}
}
public class MyService {
public static void doSomething(/*args*/) {
MyDAO.crud(/*args*/);
}
}
public class MyDAO {
public static void crud(/*args*/) {
//...
}
}
2) interfaces
@WebServlet("/welcome")
public class MyController extends HttpServlet {
private MyService myService;
public MyController() {
super();
if (myService != null) {
myService = new MyServiceImpl();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
myService.doSomething(/*args*/);
}
}
public interface MyService {
void doSomething(/*args*/);
}
public class MyServiceImpl implements MyService {
private MyDAO myDAO;
public MyServiceImpl() {
if (myService != null) {
myDAO = new MyDAOImpl();
}
}
@Override
public void doSomething(/*args*/) {
myDAO.crud(/*args*/);
}
}
public interface MyDAO {
void crud(/*args*/);
}
public class MyDAOImpl implements MyDAO {
@Override
public void crud(/*args*/) {
//...
}
}
3) something else...
Thanks.