Prototype Pattern

The prototype pattern is used when we want to reuse a lot of the attributes with the same values as on the to clone object. If the attributes used are coming from a database, we can prevent the call to a database for the attribute values by cloning the existing attributes. Let’s take a look … More Prototype Pattern

Dependency Injection

With dependency injection we give our class the attributes it needs through the constructor or the setter. If an attribute is required hand it through the constructor is the preferred way (in frameworks like Spring it’s advised by the framework). A dependency injection example for bread looks like this. water public class Water { private … More Dependency Injection

Liskov Substitution

Liskov substitution means that parent classes should be able to be switched to child classes and all code should continue to function. The parent can be any kind of interface, abstract class or class. We go look at an example of Liskov substitution with a monster interface and 2 monsters. Monster public interface Monster { … More Liskov Substitution

Singleton Pattern

When we want to have only one instance of a class we can create a singleton. A few of the places where we would want to have a singleton class is in an abstract factory or a builder. There are lots of different way’s to create singletons. A good blog post about this is the … More Singleton Pattern

Boolean vs boolean

Boolean is an primitive type and thus can not be null. The Boolean object is a wrapper class for the primitive type boolean. Because it’s and object it can also be null, which is not possible in boolean algebra. This does make it seem less logical. When using the Boolean type the JVM converts this to … More Boolean vs boolean