design patterns

Why you should avoid conditional statements

Developers tend to use a lot of conditional statements in their code. Of course, each flow has one specific path, its own specific validations, etc. It is very natural that your code has a lot of decisions to be made at runtime, but, mostly, when you use a lot of conditional statements in specific area of your code, probably you are not using it right. Conditional statements should be used for small decisions, not big decisions, not for choosing one path of five others. (It really hurts to see chained…

Keep reading

8 design patterns that every developer should know

As a developer, you are constantly resolving problems. Many of these problems probably were already solved by other developers, so, why do we need to solve them again? You have a problem, specifically a common problem, so, you try to find out if anyone already did the job solving, before you try to resolve it, right? You probably don't want to reinvent the wheel, do ya? Design patterns are there for these situations. Unfortunately there are a lot of developers who still refuse to use a few patterns, mostly because…

Keep reading

CDI, Polymorphism and The Factory Pattern

One of the most useful things about object oriented programming is polymorphism. In fact, it makes our software have different behaviors without the need to explicit it in the code. For instance, you are writing a code to make a credit card transaction. If it is a VISA transaction, you should execute one specific action, if it is a MASTERCARD transaction, you should execute another specific action, so, the first thing you think about doing is: public void pay(Transaction transaction) throws UnsupportedCardNetworkException { if("visa".equals(transaction.getType())){ //pay with…

Keep reading