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:
[Sholey]
3. Ab tera kya hoga Kaliya?

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

[Kaalicharan]
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.

[Gladiator]
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 :-)

Sunday, January 31, 2010

Natarang

Natarang is recently released Marathi movie and in my opinion a serious contender of next year's National awards. With Marathi movie what comes to mind is laugh riot by the likes of Laxmikant Berde or Ashok Saraf. But, this movie is quite different from the current genre of movies. Setup completely in a rural backdrop and a subject that young generation might not be able to directly connect to but believe me in the end of the movie, you will be completely soaked into it. Mind you, language spoken is not polished too; though two of us who grew up in Maharashtra found it hard to decipher each and every word.
Natarang is a story of a village labourer with a strong likening towards Tamasha. He has a family to support who does not quite approve of his Tamasha indulgence and is finding it very difficult to meet ends. The story tries to do justice to each character involved and manages to do quite well in it. In my view, movie could have been longer and could be higher on sentiment-count, but creator have kept it a fast paced especially in the later half. There are no super-heroes in movie, every character is shown constrained and close to reality (with grey shades in Mayur's words). Tamasha being the central theme of the movie, there are many song and dance sequences, both of which being convincingly handled by the people involved. Finally, it is a story of triumph of one man's passion and perseverance. All the actors have performed very well and efforts put in by Atul Kulkarni are quite exceptional and evident. Finally bonus of this movie is new actress "Sonalee", that girl just blew our minds off...enjoy some of her photos here. ;-)
Guys, if you know Marathi, you simply should not avoid this movie, the songs would be quite enjoyed in a theater only, don't miss it for sure.

Tuesday, January 26, 2010

Not a penny more, not a penny less

This weekend I had a déjà vu moment, I was cleaning up the house and bumped into a dusty old book, 'Not a penny more, not a penny less.' I hoped the book to be good going by the reputation of the author, Jeffery Archer. Reading the teasers of the book, I was even more drawn to the book as it involved a favorite subject of mine the stock market.
The story revolves around a stock market wizard who is pretty much a living rags to riches story himself and earned a dubious reputation for his not so ethical trade practices. In one such operation of his, four un-connected people fail pray to his trap and losing a healthy sum of money. The misery unites them to take revenge and thus the plot of 'Not a penny more, not a penny less' unfolds. The book sketches few characters really well the shrewdness of a stock market mogul, organization qualities of a professor, the practicality of medical profession and the winnings of a charmer :-)
The story has enough twists and turns. I would not say it tops the best novel list for me but it is a very light hearted story and a good time-pass. And yeah that is how I spent the Republic Day holiday.

Thursday, January 14, 2010

Life

World gifts you what it wants to give away and not what you want to have.

Monday, January 11, 2010

That time of year again

It is that time of year again, when I do new resolutions for the coming year, not that all the vows see 31st night's celebration as most of them do not survive long. But, being the ever-optimist I am, I would not hold back. So, before starting with the resolutions, it would be better to take stock of last year's resolutions. I am a modest person, there were only three commitments:
1. Loose 5Kg of weight.
2. Write 2 blogs each month.
3. Read 1 book each month.

And how did I fare at the end of year:
1. Gained 4Kg....very very bad.
2. Wrote 20 write-ups (excluding quotes)...not bad
3. Read around 4 books...umm..very bad.

This year, the list is going to be about getting bugs fixed from last year with one being dropped. I would not set a goal on number of books, it just takes away the fun of reading books. I hope this year the fate won't be similar to earlier ones. So, this year's list is:
1. Loose 9Kg. (tough)
2. Write 2 blogs each month. (achievable...just completing one ;-) )
3. Do a better financial planning (I am going to get possession of my house this year, really looking forward it :-) )