In Search Of Resemblance
Our civilization has undergone several stages of development through different revolutionary concepts. But the idea behind all the revolutionary concepts had something in common. It was to put society in a better shape. The latest among all is the Information Technology revolution. This is basically an effort for an effective information management and faster resource mobilization. This again is based on another technical revolution, which is nothing but the Computers, both in terms of Hardware/Software. We can compare this Hardware/Software situation with something like this, a horse with a jockey. As the jockey rides the horse, the software rides the hardware. The better the jockey (Software) is, the better the stunts we get to see. But then, between this jockey and the horse where is the interface? The interface is the set of instructions. This predefined set of instructions is the medium through which the interaction is carried out or in other words forms the language. That is to say, a language is nothing but a mode of communication with a specific meaning attached to every instruction. Why do we communicate? It is basically to get some works done like expressing our feeling etc. etc. if there wouldn't have been any need for communication, then probably we wouldn't have required any language. When a baby is born, it picks up the instructions from his/her mother tongue and the meaning attached to those instructions and slowly registers them in its memory. In the process, the baby starts communicating with others. Two people from two different communities cannot communicate with other, because one cannot decipher the meaning with the sound or script of the other. A language is thus the basis for communication, but then how do we can communicate effectively. It's only when we can express ourselves with something that is close to nature or rather comparing what we want to express with some natural phenomena. For example, if we say that the water is as cold as ice, the ice being a unique object in the nature with its unique properties we can immediately have a feel of the coldness. Even a sentence like this:
"Whilst the lagging hours of the day goes by, Like windless clouds over a tender sky."
It's just the simile with the nature that has put enough punch in the sentence and that's where the beauty lies. A language gets rich when it moves close to the nature, because we cannot express ourselves with some alien thoughts of which we don't have a feel.
The invention of integrated chips led to the development of the microprocessors and subsequently the invention of Computers. The computers are digital machines and interaction with the machine too requires a language. Over the years, good number of languages has been developed, lot of which has objectives of their own. Out of these, C is considered to be a very good general-purpose language and hence considered to be a standard. In this section, we try to correlate the development of the programming languages with the nature in the light of C. It has known to us that there exists around one hundred and few elements in the nature leaving aside the manmade elements. These atomic elements combine with itself to produce molecular elements. But then the atomic or molecular elements alone are not responsible for the formation of nature. There are numerous Compound elements, which are there in the nature.
Let's take an example. Two Hydrogen atoms together form a Hydrogen molecule. Then the two Hydrogen atoms and an Oxygen atom combine chemically together to form a molecule of water. Now, considering the case of water, the information or data that we will be interested upon is the number of composing elements and the different types taking part in the chemical reaction and subsequently the properties evolving out of the compound element. Here, two Hydrogen atom and one Oxygen atom is the data, Hydrogen and Oxygen being the data type. Once water is formed, water itself becomes a unique data type with its unique properties. Thus this composition is a logical framework with which water can be created, but not a reality. It becomes a reality only when we really create them. The objects created under this logical framework becomes unique and it is technically same everywhere, be it the waters of Ganges, or of Thames, or of Amazon. Once it becomes a new data type, we can then say 500 gallons of water instead of bothering ourselves with the data of actually how many Hydrogen and Oxygen atoms are there in 500 gallons of water. This is what is called abstraction (one of the primary concepts of Object Oriented Paradigm).
The same concept has been applied in the programming languages. In C -
float represents the basic data types and we can consider them to be the atomic elements or atomic data types. But these atomic data types have their own limitations. For example, if we are to store hundred values of the same data type then we have to create hundred variables. This is naturally cumbersome. To overcome this, the concept of molecular elements was introduced. The byproduct is the concept of array. i.e., put the elements of the same type together. As it has been mentioned, that the atomic and molecular elements alone are not responsible for the formation of the nature. So, the realistic approach would be to move close to the nature. The output was the concept of Structures. It is Structures where the basic elements are put together in the same place just like the compound elements.
This is where the C language ends
It is possible to put together different element data types in the same place through Structures, but then this was not in perfect agreement with the nature. The reason being the Structures definitely revealed the composition of the compound element, but unlike the natural objects, it could not reveal the properties of the structure. Let's take the example of water again. As soon as, water is formed certain characteristics or properties like boiling point, shape etc. etc. gets associated with it, for which water becomes a unique object. In other words, every single object in this universe is unique just because of its properties. Let's take another example. Water is composed of two Hydrogen atoms and one Oxygen atom, whereas Hydrogen Peroxide is composed of two Hydrogen atoms and two Oxygen atoms. The basic data types in both cases were the same only differing in number of elements or data, which is responsible for the entirely different characteristics in the natural objects. This is where the Structures were differing from the natural Compound elements. We can have two different Structures that have the same composition but only differing in their name or identifier. The Structures never revealed any properties as such. We cannot impart properties as the number of composing elements impart in the natural objects. This shortfall was fulfilled through the concept of classes, which was introduced with the evolution of the finest programming paradigm namely - The Object Oriented Programming Concept. (Technically speaking, the evolution of Object Oriented Paradigm was from different angle, which we would be discussing in the next section). It is this class where the concept of properties or behavior is put together into Structures using functions or methods. Thus, a class is an extension of the idea of the Structures imparting its properties through functions. It is to be mentioned here that by Structures or Classes we define new data types (as we have mentioned that water becomes a new data type). When a Class is created, it is only a logical framework, but not a physical reality. It is only when objects are created for a particular Class memory is allocated, and only then it becomes a physical reality.
The concept of Object Oriented Programming principle came into existence because of the limitations in data security in the earlier programming concepts. The early programming languages such as Basic are called Process Oriented Language, which means that the jobs to be done are followed in a step-by-step sequence. These languages were OK for small programs. But as the length of the programs grew longer, the control statements such as '
goto' proved to be fatal and the complexity of the programs could not be handled effectively and efficiently. It was only then the concept of Structured Programming Concepts came into existence. The concept was dividing the programs into smaller modules and then getting the modules connected. C is a structured language. The modules in C were divided into functions. These functions were connected by passing parameters. To limit the number of parameter passes, those which are utilized by different modules were declared as Global variables. This concept was again OK for smaller programs. But as the size and the complexity increased, when one function sets the global variable to some value, the function changed it. In the process, the results were incorrect. Ultimately what turns out in both cases is that we lay stress only on the steps of execution, but we are hardly bothered about the data for which all these has been done. This laid the groundwork for thinking new concepts, which would give absolute data security and OOPs evolved.
The first and the most important principle of Object Oriented Programming Principle is the data encapsulation. This is the first step towards achieving goals towards data security. In the natural objects, the data security comes through various forces at the atomic and molecular level. For example, two Hydrogen atoms and one Oxygen atom put to form water. But if we break this structure, it does not remain water any more. The data security in languages implementing OOPs is achieved through various access specifiers such as
public - an implementation of the interatomic and molecular forces in the natural objects. The second important aspect of the Object Oriented Programming Paradigm is Inheritance. This is nothing but inheriting the properties of a Superclass or Parent class to another class which is called the child class, just as the children inherits the properties from their parents. This property of nature finds great significance in the field of programming, because we don't have to declare the same properties in different classes again and again. We just declare the significant properties to a class and go on inheriting these classes to other classes, which needs to implement or reflect such properties in addition to its own properties. This approach naturally saves a lot of complexity and is in concert with natural phenomena.
The third important aspect of Object Oriented Programming Paradigm is the concept of Polymorphism, which means one face and multiple interfaces. This concept is again very much there in the nature. A person can be father of someone, brother of someone and friend of someone else. But when the question of interaction comes, the same person behaves depending on the relationship. In fact, the concrete definitions in relationships describe the person's personality. This concept of Polymorphism is achieved through functions having the same name, but their execution depending on the context. Function overloading is a way of implementing Polymorphism. Then there are cases of run-time polymorphism etc. etc.
Besides these basic properties of encapsulation, Inheritance, Polymorphism some more concepts came into existence such as Abstract Classes, Inner/Outer Classes. Abstract classes are defined in such a way that there are only function declarations within the class. The functions are not defined inside the class and hence the classes are named as Abstract classes. These classes are being inherited and the functions are defined where they are implemented. Although these concepts seems to sound abstract, but a close look at the nature reveals that these concepts are there in the nature. Let's take the example of water again. The shape of water is abstract. It takes the shape of the container where it is kept. i.e., the shape gets defined where it is implemented.
When a class is defined inside another class, the class within is called the inner class and the class that is containing the inner class is called the outer class. In such cases an object of the outer class cannot directly access the resources of the inner class. It has to pass request via the object of the inner class, which is to be defined inside the outer class. The inner class can access the resources of the outer class, but not the vice versa. The example in nature that illustrates this situation best is a baby in the womb. If you want to feed the baby, you have to feed the mother. You cannot feed the child directly. This is called the concept of Containment - a very important concept that has a great impact in the programming languages.
The basic three concepts of OOPs namely, data encapsulation, inheritance and polymorphism along with the other properties has not only increased data security, but also evolved into a rich programming style. In fact, its drift towards the nature and has made things more realistic and logical. So, let's get harmonious with the 'Mother Nature'.