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