Sunday, July 26, 2009

Object Oriented Life

Being in the software industry for more than 4 years, software professionals like me can’t help applying computer programming principles in everyday life. The otherwise routine activities and stages in life start getting “Object Oriented”. “Object oriented” here won’t mean leading a life for an objective (no spiritual stuff intented), rather a few examples where life follows the computer programming principles.

The social structure of human beings itself seems to follow Object Oriented Programming (OOP) approach; consider various roles that a person plays throughout his life, be it a son, a brother, a husband or a father. These roles are the classes (“Son”, “Brother”, “Friend”, “Husband”, “Father” etc.) which all are derived from a common base class called “Human”. While “Human” class declares the common properties (Name, family name, sex, age, etc.) and implements a few methods, every derived class has its own set of properties and methods which are called at diferent stages of life. We also can consider “Human” class itself being derived from “Life” interface which defines methods that are common in all living beings, like walking, eating, running, breathing, etc. In this way, life does seem to justify “Inheritence” which is an inherrent part of OOP.

Another important aspect of OOP is Polymorphism, or implementing the same method with different arguments. Daily activities like driving, reading, writing, shopping follow polymorphism. Driving a car seems an overloaded method of driving a bike, similarly reading an online article, email seem to be overloaded methods of reading a physical newspaper.
Encapsulation and use of private variables is as important in human life, as in a computer program. ATM Pin(s) are always (and should alwasys be) private.

A typical human working day personifies a well coded computer program, where different services run in the background, different classes are initialised and flushed at different times and different methods are invoked as per need. Day begin when an alarm clock (background windows service or scheduler? :-)) gets us up. Different methods like Bathing(), HaveBreakfast() are invoked, while activities like WashingClothes(), PreparingBreakfast() are managed by other helper classes like washing machine and microwave owen. We use an overloaded method of Travel() which internally invokes and overload of Driving() as per the argument we pass (bike or car :-)). Reach office and we are into a multitasking mode. Office senior wants us to work, while our multi-task ready processor wants us to parallely trade on an online share trading portal, without hampering the office output.
A small share of our time is also spent in debugging, i.e reviewing the code on which our life runs. Reviewing self and financial health, reviewing the health in our relationships seem to happen in the debug mode. After office hours, we again implement the Travel() overload to reach home, flushing all the unwanted objects (office, share trading etc.) and calling other methods as per need. Not to forget, the day has also encountered a few bugs like unwanted personal loan calls :-)
Handling Events is an important part of a computer program, and equally important is safely handling unwanted events, whom in programming terms, we call “Exceptions”. As in computer, so in personal life, these exceptions should safely be handled. Loss of job, loss of life, health emergency are all examples of real life exceptions which normally are (and should be) planned smartly by way of appropriate insurance and investments. After all, a well built code leads to a well run program :-).

Object orientation improves the quality of code, rendering reliable results. Similarly, a life that follows some simple object oriented principles can definitely improve the quality of our life, after all, life personifies a computer program :-).