General OOP concepts

With the rapidly changing world and the highly competitive and versatile nature of industry, the operations are becoming more and more complex. In the view of the increasing complexity of software systems, the software industry and software engineer continuously new approach for the software design and development. The increased complexity had become the chief problem with compute programs in traditional languages. Large programs, because of this complexity are more prone to errors, the software error can be expensive and can be life threatening. The most adopted and popular programming approach, structured programming approach, failed to show the desired results in terms of bug-free, easy to maintain, and reusable programs, the latest programming approach, Object-Oriented-Programming (OOP), offers a new and powerful way to cope with this complexity. Its goal is clearer, more reliable, more easily maintained programs. This article introduces general OOP concepts that the traditional languages like C, Pascal, COBAL and BASIC lack in the new generation languages (Object-Oriented Languages) support.

 

Evolution of software

A program serves the purpose of commanding the computer. The efficiency and usefulness of a program depends not only on proper use of commands but also on programming languages it is written in. the major types of programming languages offer different features of programming.

Low level language (i.e. , machine language and assembly language) are machine oriented and require extensive knowledge of computer circuitry. Machine language, in which instructions are written in binary code (using 0 and 1), is the only language the computer can execute directly. Assembly language, in which instructions are written using symbolic names for machine operations (e.g., READ, ADD, STORE etc.) and operands, makes programming less tedious than machine language programming. However, assembly program is then converted in to machine language using assembler software.

High level language (HLLs), on the other hand, offer English like keywords, constructs for sequence, election (decision) and iteration (looping) and use of variables and constants. Thus it is very easy to program with such languages compared to low level languages. The programs written in HLLs are converted in to machine languages compared to low level languages. The programs written in HLLS are converted in to machine languages using compiler or interpreter as a computer can work with machine language only.

A programming language should serve two related purposes:

(i) It should provide a vehicle for the programmer to specify actions to be executed and

(ii)It should provide a set of concepts for the programmer to use when thinking about what can be done. The first aspect ideally require a language that is “close to the problem to be solved” , so that all important aspects of a machine are handled simply and efficiently in a way that is reasonably obvious to the programmer. The second aspect ideally requires a language that is “close to the problem to be solved” so that the concepts of a solution can be expressed directly and concisely.

The low level languages serve only the first aspect i.e., they are close to the machine and high level language serve the second aspect i.e., they are close to the programmer. However, the languages ‘C’ and ‘C++’ serve both the aspects; hence can be called as ‘middle level languages’.

 

Programming paradigms

By programming paradigm one means a way of thinking. Paradigm means organizing principle of a program. It is an approach to programming.

Since the invention of the computer, many programming approaches have been tried such as procedural programming, modular programming, structural programming etc. The primary motivation in each case has been the concern to handle the increasing complexity of programs that are reliable and maintainable.

Let us discuss these different programming paradigms and key languages mechanisms necessary for supporting them.

Procedural Programming

A program in a procedural language is a list of instructions where each statement tells the computer to do something. The focus is one the processing, the algorithm needed to perform the desired computation. This paradigm is :

Decide which procedure you want: use the best algorithms you can find.

Languages support the paradigm by providing facilities for passing arguments to functions (sub-programs) and returning values from functions (sub-programs).

In procedural paradigm, the emphasis is on doing things. What happens to the data? Data is after all, the reason for a program’s existence. The important part of an inventory program isn’t function that displays or checks data; it is the inventory data itself. Yet data is given second-class status while programming.

Modular programming

With the increase in program size, a single list of instructions becomes unwieldy. Thus a large program is broken down in to smaller units i.e., functions (sub-program). The idea of breaking program in to functions can further be extended by grouping a number of functions together in to a large entity called module, but the principle is similar: grouping of components that carry out specific tasks.

A set of related procedures with the data they manipulates is called a module.

The programming paradigm, also known as ‘data-hiding principle’ states:

Decide which modules you want: partition the program so that data is hidden in modules.

Where there is no grouping of procedures with related data, the procedural programming style suffices. The techniques for designing ‘good procedures’ still apply on each member procedure of modules.

In modular programming, since many modules (or functions) access the same data, the way the data is stored becomes critical. The arrangement of the data can’t be changed without modifying all the functions that access it.

Another problem associated with procedural and modular programming is that their chief components- functions etc. do not model the real world very well. For instance, a procedural program for library maintenance aims at the operations Issue, Return etc. whereas the real world entities are Books. But ‘Books’ are given second class status in the program. We will understand this problem more clearly in the next paradigm-the object oriented paradigm.

The object oriented programming

To understand this most recent concept among programming paradigm, let us take an example. We have to prepare lot of dishes that involve baking; for instance cake, biscuits, pie, dhokla, pastries, buns etc. we have to write programs for it. Using procedural programming paradigm, we’ll have to write separate programs for every recipe and each program will be containing instructions for operating oven. Ovens are used to make a lot of different dishes. We don’t want to create a new oven every time we encounter a new recipe. Having solved a problem once, it would be nice to be able to reuse the solution in future programs. But the procedural programming paradigm suffers from this drawback. Though functional software reuse is theoretically possible, but it hasn’t work very well in practice. The large amount of interaction between conventional functions and its surroundings make reusing them difficult.

However, if the same problem is solved using object-oriented approach, it’ll not only be less complex but also make software reuse feasible and possible. The object-oriented approach views a problem in terms of objects involved rather than procedure for doing it.

Object is an identifiable entity with some characteristics and behavior.

For instance we can say ‘Orange’ is an object. Its characteristics are: it is spherical shaped, its colour is orange etc. Its behavior is juicy and it tastes sweet-sour. While programming using OOP approach, the characteristics of an object are represented by its functions associated. Therefore, in OOP programming object are represents an entity that can store data and has its interface though functions.

The above mentioned problem of baking dishes, in OOP approach, will be viewed in terms of object involved (i.e., OVEN) and its interface (i.e., the functions representing its working). This not only results in simple program design but also reduces software cost.

To understand this concept more clearly, let us consider another example. Let us simulate traffic flow at a red light crossing.

As you know, procedural programming paradigm focuses on the procedures or the working action.

Using procedural programming paradigm, the above said problem will be viewed in terms of working happening in the traffic-flow i.e., moving, halting, turning etc. The OOP paradigm, however, aims at the objects and their interface. Thus in OOP approach, the traffic-flow will be viewed in terms of objects involved. The objects involved are: cars, trucks, buses, scooters, auto-rickshaws, taxis etc.

With this elaboration, the concept must be clear enough to proceed for the OOP paradigm definition. But before that let us understand another very important term class.

 

 

 


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments