Saturday, February 27, 2010

Strategy Pattern

Few weeks back I started reading about Design Patterns and Madhur kept on nagging (he reads it as encouraging) me to blog about it. So, I am kicking off a series of blogs on design patterns, starting with the Strategy Pattern.

As the name suggests, the pattern deals with how to organize different strategies in your application. Before starting with the pattern, following are the basic principles that one needs to grasp:
1. Encapsulate what varies.
2. Favor composition over inheritance.
3. Program to interface than implementation.

So, let me formally introduce you the Strategy Pattern, it is a design solution wherein you combine a family of algorithms, organize it separately in interfaces, prepare it concrete implementation and in your client-code work exclusively with the interface.

Let me give you an example, suppose there is a base class animal with concrete implementation as in dogs, leopard, fish etc. All these animals exhibit moving behavior, but differently as in walking or leaping or swimming. Thus, we can write a interface MovingBehavior with move as its method. It should have WalkingBehavior, LeapingBehavior and SwimmingBehavior as concrete implementations. The base class Animal would maintain a MovingBehavior reference with getter and setter method. Thus, for each animal, we need to specify its corresponding MovingBehavior. It has one more advantage, if our dog decides to swim, we can appropriately set its behavior.

I hope this served as a good introduction to Strategy Pattern. If this blog let you down, you know where to send your hate messages (he thinks good wishes) :-)

PS: I am reading Head First DP, thus the content might appear strikingly similar, its a great book to read, in fact the whole HeadFirst series is awesome.

Thursday, February 25, 2010

The Sachin Tendulkar

What more we need to say about this dude, every other month he is breaking some or the other record. In my opinion he is the greatest cricketer to have graced the game as far as I have seen in last 20 odd years. I rank Rahul Dravid very highly but Sachin beats him with sheer genius and attitude. Playing for over two decades now and attributed with success that hardly could have ever managed in history, this guy has never been known for any star-tantrums. The humility and character he brings to game truly makes him the biggest gentleman of the game.
Sachin has graced the game for two decades now and his strive for excellence still continues for me which is more evident by the dive he attempted in last game to save valuable boundary than today's effort.
Even if you are naive and you do not hear from experts of game but if you see get to see Sachin batting, his caliber is evident with the perfection, poise and follow through of his shots. For quite some time now, there has been expert advice that Sachin should retire but if we look at the way he has played for last year or so, boss I don't think so this run-machine is going to stop anytime soon and pretty soon we will see a century of centuries. Apart from this, there are always comparison made between Sachin, Pointing, Lara etc. Statistically speaking we might be tempted to make such a comparison but if you take a look at some factors as in the kind of atmosphere a person has played, the team combination and the character one has built, un-arguably Sachin beats everyone hands down with carrying expectations of over billion, rubbing shoulders with players half his capabilities.
For all the talent he possessed, things I admire more of this person is his always ready to take on attitude, humility and efforts to keep on going. Truly he is not only a great cricketer but a great person. Wishing him all the successes for his last un-fulfilled cricketing achievement which is to win ODI World Cup for India.

Thursday, February 4, 2010

Favorite movie dialog

There is a contest run by my favorite blogger (GreatBong), the winner of the contest would get a book authored by GB himself. The contest requires you to write your favorite movie dialogs. The rules and other entries are listed here.
I could probably write tons of quotes from Hindi movies but to maintain equality with number of favorite English movie quotes, I am going to restrict to three. So, below is the list of my most loved, used and abused movie quotes of all time, yenjaay :-)

Fultoo Bollywood:
3. Ab tera kya hoga Kaliya?

2. Yeh bachon ke khelne ki cheez nahin! Haath kat jaaye toh khoon nikal aata hai.

1. Ise liquid oxygen me fek do, liquid ise jeene nahi dega aur oxygen ise marne nahi dega, ha ha ha.

From Hollywood:

[Blood Diamond]
3. Sometimes I wonder will God ever forgive us for what we've done to each other? Then I look around and I realize... God left this place a long time ago.

2. My name is Maximus Decimus Meridius, commander of the Armies of the North, General of the Felix Legions, loyal servant to the true emperor, Marcus Aurelius. Father to a murdered son, husband to a murdered wife. And I will have my vengeance, in this life or the next.

[Matrix Reloaded]
1. Choice, the problem is choice.

Now, I need five of you people to qualify for the contest, that way you could probably enter the contest too, so guys get on your keyboard and punch in your favorite dialogs and possible win a book :-)