Programming Paradigms

The word “paradigm” means an example that serves as a pattern or a model. Programming paradigms are the different patterns and models for writing a program. The programming paradigms may differ in terms of the basic idea which relates to the program computation. Broadly, programming paradigms can be classified as follows:

1. Structured Programming,

2. Object-Oriented Programming (OOP), and

3. Aspect-Oriented Programming (AOP). AOP is a new programming paradigm.

Earlier, the unstructured style of programming was used, where all actions of a small and simple program were defined within a single program only. It is difficult to write and understand a long and complex program using unstructured programming. The unstructured style of programming is not followed nowadays.

Structured Programming

·         Structured programming involves building of programs using small modules. The modules are easy to read and write.

·         In structured programming, the problem to be solved is broken down into small tasks that can be written independently. Once written, the small tasks are combined together to form the complete task.

·         Structured programming can be performed in two ways—Procedural Programming and Modular Programming

·         Procedural Programming requires a given task to be divided into smaller procedures, functions or subroutines. A procedural program is largely a single file consisting of many procedures and functions and a function named main (). A procedure or function performs a specific task. The function main () integrates the procedures and functions by making calls to them, in an order that implements the functionality of the program. When a procedure or function is called, the execution control jumps to the called procedure or function, the procedure or function is executed, and after execution the control comes back to the calling procedure or function.

·         Modular Programming requires breaking down of a program into a group of files, where each file consists of a program that can be executed independently. In a modular program, the problem is divided into different independent but related tasks. For each identified task, a separate program (module) is written, which is a program file that can be executed independently. The different files of the program are integrated using a main program file. The main program file invokes the other files in an order that fulfils the functionality of the problem.

                        Structured programming

In structured programming, the approach to develop the software is process-centric or procedural. The software is divided into procedures or modules, based on the overall functionality of the software. As a result, the procedures and modules become tightly interwoven and interdependent. Thus, they are not re-usable.

·         C, COBOL and Pascal are examples of structured programming languages.

Object-Oriented Programming (OOP)

OOP focuses on developing the software based on their component objects. The components interact with each other to provide the functionality of the software. Object-oriented programming differs from procedural programming. In OOP the software is broken into components not based on their functionality, but based on the components or parts of the software. Each component consists of data and the methods that operate on the data. The components are complete by themselves and are re-usable. The terms that are commonly associated with object-oriented programming are as follows:

·         Class is the basic building block in object-oriented programming. A class consists of data attributes and methods that operate on the data defined in the class.

·         Object is a runtime instance of the class. An object has a state, defined behavior and a unique identity. The state of the object is represented by the data defined in the class. The methods defined in the class represent object behavior. A class is a template for a set of objects that share common data attributes and common behavior.

·         Abstraction, Encapsulation, Inheritance and Polymorphism are the unique features of object- oriented software.

·         Abstraction allows dealing with the complexity of the object. Abstraction allows picking out the relevant details of the object, and ignoring the non-essential details. Encapsulation is a way of implementing abstraction.

·         Encapsulation means information hiding. The encapsulation feature of object-oriented software hides the data defined in the class. Encapsulation separates implementation of the class from its interface. The interaction with the class is through the interface provided by the set of methods defined in the class. This separation of interface from its implementation allows changes to be made in the class without affecting its interface.

·         The Inheritance feature of object-oriented software allows a new class, called the derived class, to be derived from an already existing class known as the base class. The derived class (subclass) inherits all data and methods of the base class (super class). It may override some or all of the data and methods of the base class or add its own new data and methods.

·         Polymorphism means, many forms. It refers to an entity changing its form depending on the circumstances. It allows different objects to respond to the same message in different ways. This feature increases the flexibility of the program by allowing the appropriate method to be invoked depending on the object executing the method invocation call.

·       C++ and Java are object-oriented programming languages.

Aspect-Oriented Programming (AOP)

Aspect-oriented programming is a new programming paradigm that handles the crosscutting concerns of the software. The crosscutting concerns are the global concerns like logging, authentication, security, performance, etc., that do not fit into a single module or related modules. In OOP, the business logic or core concern is encapsulated in well-defined classes. However, the code for implementing crosscutting concerns is intertwined with a number of related classes or modules and gets scattered in the different classes of the software.

AOP is a new paradigm that focuses on the issue of handling crosscutting concerns at the programming language level. It helps the programmer in cleanly separating the core concerns and the crosscutting concerns of the software. AOP introduces a new modular unit called “aspect” that encapsulates the functionality of the crosscutting concerns. Aspects of a system are independent elements that can be changed, inserted or removed at compile time, and even reused without affecting the rest of system. Aspects are similar to the classes of object-oriented programs; however, they implement the crosscutting concerns. At compilation time, the classes of object-oriented programs and the aspects are combined into a final executable form using an “aspect weaver”.

·         AspectJ and AspectC are examples of aspect-oriented programming languages.

After having selected a suitable programming paradigm for the program to be written, the coding of the logic of a program has to be done in a computer programming language. For the purposes of coding, the programmer checks the requirements and suitability of the task, and selects from among the programming languages available for the selected programming paradigm.

Characteristics of a Good Program:

A program written using any of the programming language must have certain characteristics, which makes it a good program. Some of the key characteristics of a good program are as follows:

·         The program should be well-written so that it is easily readable and structured.

·         The program should not have hard-coded input values. This implies that it should not be written to work for a particular input value, but must be a general program (also called generic program) that accepts input from the user.

·         The program should also be well-documented so that later the author or any other programmer can understand the program.

·         Since new and better operating systems keep coming up, a program must be designed to be portable, i.e. with minimum dependence on a particular operating system.

A program comprising of the above features is generally characterized as a good program.