Posts

Showing posts with the label Behavioral design pattern

Mediator design pattern.

Image
Background – This design pattern shows a path and encourage us to find new problem statements (or opportunities) and a simple way to solve them. Solution of a huge problem, for example, how one node in an extensive system is going to talk to another node of the existing system? Shadi.com may be a very classic example of mediator design pattern. Imagine a time before Shadi.com. Or any other matrimonial website. All parents, who desperately want their kids to get married, may like to talk to so many different people (or say, like to see many options). For example, if 100 people are of the same caste (of both gender). And can pair, then it will take factorial 100 (!100) combinations. They can pair ( plus they should be having the address of all other families, to connect and match pairs). Because it is a very tedious job. People quit searching after they reach 10 or 15 options. B ut they don’t want their kid to choose someone of his/her own choice; In India :P. Well, this is ...

Memento design pattern.

Image
Problem statement – I am hoping that we all are very much familiar with text Editors (i.e., notepad++, text pad, MS word, etc.). The most important things we do there (apart from copy and pest things from one place to another place) undo and redo. Or for game lovers, many times we perform undo step to rollback our game in previous position. We wish our life could also give these two important command – undo and redo, but unfortunately, it is not there :(  Now the question is, how do we achieve tremendously helping two commands undo and redo? Background – So we have a requirement of storing an object. The question here is, w hat we have understood from OOAD designs; is do not assign any responsibility to any class. If that responsibility is not related to the class's core behavior.  For Instance doing undo and redo is not the core behavior of TextEditor class. So we would implement a class who perform undo and redo for TextEditor class. Whe...

Command design pattern for beginners.

Image
Prerequisite -  Please read  Controller design pattern  first, t o understand command design pattern better. Background -  This design pattern is applicable for broad applications. I am hoping that you have a good understanding of the  Controller design pattern. Implementing controller would be very difficult without command if you are designing large applications (say 50+ modules).  As we know, the controller is a singleton, and it has to delegate control/work (to one or maybe more than one) modules according to the nature of the request. Writing code to implement this will be very huge (in lines of code), and it will become tough to maintain (that code) in the maintenance phase.  The solution to this problem is the Command design pattern. Let's understand the command design pattern with a classic example - Example -  What operations do we perform in railway web site? Reserve tickets. Cancel tic...