anti-if campaign

The problem is not the ‘if’ statement, it is the programmers who write bad code. EDIT: Also, as others have pointed out, you should be using polymorphism (if available) when you are using if statements to check the type of an object, but if statements in and of themselves are very useful and fundamental constructs.

When do we need decorator pattern?

The Streams in Java – subclasses of InputStream and OutputStream are perfect examples of the decorator pattern. As an example, writing a file to disk: File toWriteTo = new File(“C:\\temp\\tempFile.txt”); OutputStream outputStream = new FileOutputStream(toWriteTo); outputStream.write(“Sample text”.getBytes()); Then should you require some extra functionality regarding the writing to disk: File toWriteTo = new File(“C:\\temp\\tempFile.txt”); OutputStream … Read more

Monostate vs. Singleton

monostate and singleton are two faces of the same medal (global state): monostate forces a behaviour (only one value along all class instances) singleton forces a structural constraint (only one instance) singleton usage is not transparent i.e.: Singleton singleton = Singleton.getInstance(); monostate usage is transparent i.e.: MonoState m1 = new MonoState(); MonoState m2 = new … Read more

Using a strategy pattern and a command pattern

I’m including an encapsulation hierarchy table of several of the GoF design patterns to help explain the differences between these two patterns. Hopefully it better illustrates what each encapsulates so my explanation makes more sense. First off, the hierarchy lists the scope for which a given pattern is applicable, or the appropriate pattern to use … Read more

REST API Login Pattern

Principled Design of the Modern Web Architecture by Roy T. Fielding and Richard N. Taylor, i.e. sequence of works from all REST terminology came from, contains definition of client-server interaction: All REST interactions are stateless. That is, each request contains all of the information necessary for a connector to understand the request, independent of any … Read more