Thursday, June 6, 2013

Design pattern story - the beginning

I've been struggling to explain design pattern that I feel is easier to understand. So after reading "Storytelling for Software Professionals" by Arjen Uittenbogaard on May/June issue of IEEE Software, I decided to give it a try and explain design pattern in term of a story. This is a story I made up to serve as the base to explain design patterns.

----------------------------------------------------------------------------

Once upon a time, there was a farmer named Todd. Todd loves zucchini, so he spent all his time figuring out how to plant the perfect zucchini. After years of trial and error, he finally found a way to plant the perfect zucchini. He invited everyone in the village over to try his perfect zucchini. They were all amazed at how delicious they were! Everyone asked Todd to show them how he did it. "The secret," Todd said, "is to water the plant before sunrise." Everyone thanked Todd and went home to plant their own zucchini.

One day, Todd met Mary, a beautiful girl from a nearby village. The two fell in love and got married. Seeing the empty space on Todd's land, Mary asked if he can plant carrot because it's her favorite vegetable. As newlyweds, Todd was still in love. So he happily went to Alexander, the best carrot farmer and asked for instructions. "The secret," Alex said, "is to water it at 7AM and 6 PM to ensure the carrot has enough water to grow." Todd thanked Alex and happily went home. After months of hard work, Todd had a whole lot full of perfect carrots. It was sweet and crunchy, just as he expected. His wife was so happy. They hug, they kissed, and the next thing they know, they had a baby.

When the baby was born, Todd tried to feed the baby with his perfect carrot. But the baby couldn't eat it. It was too crunchy.

"You should ask Alex on how to plant baby carrot that has no crunch," his wife advised.

So Todd went back to Alex and explained his problem.

"If you want the carrot to be less crunchy, water it more and pull it up earlier," Alex, the carrot farmer said.

Todd did as instructed. And surely, he had carrot with no crunch. As the baby grow older, Mary wanted to add a little crunch to the carrot. But carrot takes months to grow. By the time Todd got the carrot to have a little crunch, the baby was ready for the regular carrot. Plus, keeping track of when to water the plant and how much water for which row becomes a little too much.

Feeling frustrated, Todd went to Alex, the carrot farmer and complained about the situation. Alex nodded understandingly, as if he had heard it before.

"Listen," Alex said. "James, my neighbor is also having a problem similar to yours. He grows the best potatoes. So I told him, if he grows me some potatoes, I'll grow the carrot for him. I can also do that for you if you grow me some of your zucchini. That way you don't have to worry about growing carrot."

"What a great idea!" Todd exclaimed. So next year, Alex grew only carrot and Todd only grew zucchini. Whenever Todd needed carrot, he goes to Alex and tell Alex the type of crunch he wants and Alex would pull it from his garden.

One day, Gwen, Mary's sister, came to visit the couple. She saw how beautiful and prosperous the village was and decided to make it her new home. Now Gwen was a very talented chef. She decided to open a soup shop to make a living. Instead of growing her own vegetables, Gwen went to Todd for zucchini, Alex for carrot, and James for potato. Because Gwen didn't have to worry about growing vegetables, she could focus on perfecting her soup. Her zucchini soup became so popular that it attracted many visitors from neighboring villages. This in turn increased her demand for Todd's zucchini. But Todd was often busy with the farm, so he didn't have time to sell the zucchini.

"Why don't we open a zucchini stand?" Mary wisely suggested. "That way, when you're busy on the farm, our son or I can sell it. The customer never have to go look for you when they want to buy zucchini."

"Great idea. Let's set up a zucchini stand in front of our house," said Todd.

So the couple set up a zucchini stand. Whenever Gwen needed zucchini, she went to Todd's stand. She didn't have to look for Todd nor did she care who is selling the zucchini. The zucchini stand did so well, Todd and Mary saved enough money to build a bigger house and send their son to school..................eh and they live happily ever after.

0 comments:

Post a Comment