Wednesday 11 January 2012

Object Oriented Programming Concepts


There are various approaches to solve a problem. Moreover, these approaches are to a great extent dependant upon how each one of us tries to analyze and solve the problem.
We have a very simple assignment:
Lets say we want to calculate a distance formula for traveling from one place to another. The distance formula has to include all the attributes of the journey. So let us see what data do we have-

Variables:
Location: Have to go from one city to another (both the cities can be anywhere in the world).
Modes of travel: Car/Bus/Train
Date constraints: Departure/Arrival Date.
Time Preference: Morning/Afternoon /Evening
Distance: Break Journey
Travel Cost. Etc
Now, we have termed these data items as “variables” because their value would be changing based upon the various choices made.
Even for such a trivial problem, there are being so many options/constraints, there are so many approaches to arrive at a decision. On similar lines, given a problem and basic resources (which also act as constraints), various algorithms can do the task programmatically. An algorithm is nothing but the thought process/approach involved.
A good approach should
• Be generic so that it works well with all possible combinations of inputs.
• Flexible / adaptable to absorb new inputs. (New destination, routes, rates, timings or even new mode of travel - say space travel)
• Give solutions in the desired timeframe.
• Make best use of resources available. (Optimize the solution)
• Cost effective.
• Simple enough.
   Primitively, there was a very straightforward manner to write applications. Straightforward in the sense that the various tasks in the application would be identified and would be automated. This approach did work for many scenarios but when it came to the robustness or maintenance of the application, this approach proved to be insufficient.
   In this section we will first discuss what was the procedural approach and how the design of an application be made using this approach. By trying to figure out the negative points in the approach we will then appreciate the advantages of object oriented programming by discussing it as a solution to overcome the
shortcomings of procedural programming.