Category: Design Patterns

All the stuff related to design patterns go here.

So, Singleton or Monostate?

So, Singleton or Monostate?

Continuing with the design pattern fun, lets talk about one of the most commonly used pattern, Singleton and an alternative called Monostate. I too wrote about singleton pattern relative to Joshua Bloch’s Effective Java a few days back. The Basic Difference in Two Well what is this monostate we talk about? Monostate is very similar …

+ Read More

Factory Design Pattern

Factory Design Pattern

People have been appreciating the effort I am putting in each post these days. Feels good. Moving on with another design pattern, we have the ‘Factory Design Pattern’. It is also known as the Simple Factory Design Pattern. There exists a very similar pattern named ‘Abstract Factory Design Pattern’. The difference between the design patterns …

+ Read More

Observer Design Pattern

Observer Design Pattern

As I mentioned in my previous example for Strategy Design Pattern, that the design patterns are best understood with examples. Without wasting any more time, I’ll just define our simple problem. Problem: We have a newspaper say, “GlobalTimes” (fictitious name). The newspapers usually have many readers. Now, the problem is to notify the news readers …

+ Read More

Strategy Design Pattern

Strategy Design Pattern

Design patterns are better understood when we try learning them with an example. Lets take up a problem here. Problem: Lets say there are Animals which can fly and those which cannot. Since, the world is constantly evolving, any animal can be given the ability to fly by nature, or the ability can be taken …

+ Read More

Builder Pattern For Complex Validations

Builder Pattern For Complex Validations

So, here is an extensible API for complex validations. I’ve written a small piece of code for common validations. The code can be extended to introduce more complex validations. Highlights – Builder Pattern Extensible code Non-instantiable Validation class Used a variety of concepts I discussed in the past month Here is the link to the …

+ Read More