The Designer’s Block – Party Time

As I said towards the end of Part 2, time for operation clean-up, but before that some “gyan” – check what it means in Hindi.  “Gyan” on the first of the SOLID principles.  I consider it the easiest but one of the most foundational – the “Single Responsibility Principle” – SRP.  Its simplicity is also humbling…..I reckon that if all software developers just start following this religiously, the world would be a better place.

Single Responsibility Principle (SRP)

The reason I say easiest is because we follow this principle unknowingly in our day to day life. It’s the way the world is built or the way we built the world. Look around you. What are you sitting on? A chair. What’s a chair meant for? To sit. Thats what it is meant for. Can we use the chair for something else? For example, climb on it to reach a high shelf. Sure we can, but that’s not what it’s meant for. That’s why we designed ladders. If you build a chair that is also a ladder, well you can do that, but I am sure you would not come up with an ideal chair or an ideal ladder.

The idea is not limited to things around us. It is also how we behave and work. As Human Beings, one of our key abilities is the ability to organize and plan.   Say you were charged with the “responsibility” of organizing a family event, in which all your relatives from around the world or country are going to part take. Lot needs to be done and taken care off. It is but natural that you would probably first sit down, grab a piece of paper and pen and make a high level list of things that need to be done and arranged for. If you are someone like me, you would probably start making spreadsheets and to-do lists for all the work that needs to get done. Some have an inane knack for such organizing skills and would unconsciously start doing this up in their heads. Nevertheless, there is lot of stuff to be done and you are a perfectionist by nature and want things done right. So what do you need or rather what would you do? You need HELP! In other words you need to ask for HELP and rope in people who can help you. Persons, to each of whom you can delegate a specific responsibility to, provide them the necessary details of the same, and trust that he or she takes care of it well.

Let’s continue the story and start planning the event. So in the above example, you would need a Person to handle travel for people in the family, a Person to ensure that the food and drinks are arranged, a Person to arrange for entertainment, etc. And it would help if the guys you chose are good and – optimistically – experts in these areas you would like help or delegated. Let’s stop here and not go overboard planning the event. We don’t want to end up, just having a good time and not learning something from it all. The event is fairly complex enough for us to step back and learn something. So here you are, the “Party Planner.” Let’s give each of the others a designation. The “Travel Guy,” the “Food Guy” and lastly, the “Entertainment Guy.”

So what have we learnt from all this gibberish above? Good OO is very similar to the above gibberish. In OO terms, following SRP means defining a class such that it caters to just one responsibility alone. If we were building software for the above gibberish, we would have a class called “Chair”, have a class called “Ladder,” have a class called “PartyPlanner,” have a class called “TravelGuy,” and so on.

PartyPlanner is an interesting one. It is responsible for “coordinating” or more technically, “orchestrating” the entire party.

Another more subtle realization of SRP in the real world is the basic vocabulary or words in the dictionary of any language. We have a word for everything these days, and the list is just growing as time passes by. Have you ever seen an entry in a dictionary whose meaning exceeds a line or two or have composites of “and”? Probably rarely.

Leave a comment