5 Mistakes Developers Make That Causes Bugs Without Even Noticing

Bugs Mistakes

1 – Using business code in View layer

Well, as the name says, View layer is not used for coding business logic.

Your objective when using View layer is to implement what is necessary for user interaction. Whatever framework you are using, it’s possible to implement the MVC pattern. If you can use your View logic on your Controller layer, do it!

For example, if you are using JSP, implement the logic of your View on your Servlet.

Don’t fill up your JSP with ifs or any other code. It’s better to use Taglibs instead.

2 – Using business rules in Controller layer

The Controller layer needs to be used as a connection between the View and Model layers. If you have business code in your Controller layer, check it again, and move it to the Model layer.

The Controller layer also can be used to implement the View code.

For example, if you need to load a Combobox after an action or add some format rules in your ‘inputText’ components.

You have to think, does this rule only apply to the View layer? If your answer is yes, then you should use this logic in your Controller. It does not make sense to move code that is only related to the View layer to the Model layer. The best thing you can do is to encapsulate View logic in the Controller layer.

3 – Using a lot of different architectural patterns in your project

Define a pattern to be followed in your project.

If you are using Java EE, it’s a good idea to follow an architectural pattern so that developers will more easily understand what is happening in the code.

Example:

  • (View) XHTML
  • (Controller) Managed Bean
  • (Model) Façade – (Business) EJB

4 – Creating a lot of unnecessary layers in your project

If you perceive there is a layer just invoking another layer, something is wrong.

Most times it does not make sense.

For example, you can be using the DAO (Data Access Object) layer for nothing!

If you are invoking a lot of layers in one line, all this code is unnecessary. You can remove the DAO (Data Access Object) layer and do your query in your “Service”. But remember, use your SQL code in a separate XML file.

5 – Showing code log everywhere

Hey! It’s not necessary to show code log everywhere in your application. You can just throw your Exception to the View layer and show the error in a Dialog. Remember, use words that make sense to the user!

Use your log ONLY where you catch your Exception. You will have the stackTrace, so why show log in every throw statement?

If you really need to know everything that is happening in your project, use AOP (Aspect Oriented Programming)! Don’t repeat the code for logging all your system! Imagine all the trouble you will be in if you need to change your log!

Written by
Rafael del Nero
Join the discussion

Stand Out as a Java Developer and Get Your Dream Job!

You will get the book by email in a few minutes after registering.