[Design Patterns] Template Method Pattern

Template Method Pattern – when you define and implement one or more common methods in the base abstract class, but leave some abstract methods to be implemented in the child classes depending on the context. You may invoke the concrete methods from the abstract one. The abstract method contains functionality common to all types of…

[Design Patterns] The Strategy Pattern

Strategy Pattern – is when you define some interfaces which represent the strategies for various context dependent tasks. Then you implement these interfaces in classes with alternative purposes. Sometimes during runtime, the implementations can be switched so that a new strategy is adopted. In the actual client code (that is employing the strategies), you define…

[Design Patterns] The Builder Pattern

Builder Pattern – The constructor is private. You create a nested static class called Builder. In the builder you define┬ámethods corresponding to the constructor parameters of the nesting class. Each method returns a Builder instance (return this at the end). Drawback is that you duplicate fields in the Builder. Finally you create a method called…