Posts

Template method design pattern for beginners.

Image
Problem statement – Please go through the  strategy design pattern before you continue reading this article. From the strategy design pattern, we understand that; how to build an application, where you want the user to select the approach of solving/executing problem/algorithm at run time. For a moment, imagine template methods design pattern doing the same thing but in a controlled way. Let us understand it through an example, there are 4 outstanding programmers. Like you! Writing code to solve a given problem. According to the  strategy design pattern ,  it just wants a result. Not interested in how different programmers have written their code. And what approach/strategy they have followed to solve the problem. As long as they can implement various strategies in different strategy, concrete implementation. Now those 4 programmers have joined the same software company and solves a given problem. This time as they have joined same company, all of them have ...

Strategy design pattern for beginners.

Image
Problem statement – This is one of the most straightforward design pattern from GoF. I am sure we all have played video games at some point of time in our life. Maybe on video game console, or in mobile or in computer screen, or if you are rich, then perhaps in SP3 or Xbox. And yes, many of us still like to play them. Remember, in the starting of any game. It asks you many questions. To configure the game according to your choice. Standard configuration in all games is “ Difficulty level? Easy, medium, hard ”. If we are playing it the first time, then we use to select easy. Otherwise, according to our comfort level with that particular game. We can see a noticeable difference between easy and hard levels of difficulty. Program (game) works differently according to your input, on difficulty levels. So, whenever you have such a requirement where you want to execute different algorithms depending upon the strategy set by the user. Or you have more than one way to...

Observer design pattern for beginners.

Image
Problem statement – Nowadays we all are very active on the internet. Many times we see educational web sites offering free learning with lots of topics. Different people will be interesting on various topics. And web site has millions of users. Now, if you think to design such kind software. How you will keep track of who likes which topics? If u apply simple math, billion users, one user can love as much topic as he/she wish to learn. And you have to send them regular updates related to those topics. Like new chapter has been added or modified on that topic. To all enrolled learners. U ser very from 1 to 1 million from topic to topic.  Actually we can address this problem through observer design pattern, we will see how in this article. Prerequisite – All users shall have one unique identity. For example, email IDs, or say roll numbers, or employee ID, etc. All shall be uniquely identified . You must have noticed. To register in any online for...

Bridge design pattern for beginners.

Image
Problem statement – You have got into a situation, where you need to add, or maybe remove, a new feature in the existing software system. But you have no permission to modify the current concrete implementation. How you will address that problem ?  Also, can we refine our interfaces for different requirements?  Background – As standard, we expose abstract layer to the client. The client calls to those APIs without bothering how it is implemented in your library. The library is a black box for clients. Whatever we add or remove any functionality, we have to maintain our interface in such a way, the client code shall not break. To achieve that, we can create layers of abstraction (interfaces) and separate the concrete implementation from the abstract layer. Not all interfaces need to expose the same APIs. For example, company A is using some payment gateway called X in the online e-commerce portal's transactions. But as payment gateway...