10. Good or Bad? protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req != null ) { if (req.getParameter( "type" ) != null ) { String reqType = req.getParameter( "type" ); if (reqType == "FOO" ) //Do something }}}
11. Good or Bad protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String type = req.getParameter( "type" ); if ( FORWARD_TYPE .equalsIgnoreCase(type)) { countForward(req, resp); } else if ( BACKWARD_TYPE .equalsIgnoreCase(type)) { countBackwards(req, resp); } else { throw new RuntimeException( "This type is not supported." ); }
So often people look at this as an oxymoron. As long as it works isn't that enough. Well those of us that have been doing this long enough know there's more to delivery than just getting the code to work. We all seemed to know what bad code looks like but what about good code. It's harder to nail down a generic definition that's useful in all cases but we will try anyways.
Long Methods Tight Coupling Concrete Implementation Excessive Code Branching
Short Methods Loose Coupling Abstract Implementation Minimal Code Branching