Programming paradigms are the principles or ideas that help shape the various languages ​​that you use to build software. They represent the key features of a programming language, determining its behavior. Therefore, it is safe to say that a paradigm is just as important as the syntax and semantics of a programming language. Most popular programming languages ​​use one of some sort of programming paradigm.

1. Essentials Programming

The imperative paradigm is one of the earliest approaches to programming, dating back to the 1950s. This paradigm relies heavily on the use of variables, commands, and procedures. Imperative programming uses commands to inspect and update variables to store state in a program.

A combination of commands then forms a process. Data abstraction plays an important role in data representation, which facilitates loose coupling. One of the most popular languages ​​to use the imperative paradigm is C. This programming language supports only work procedures.

An imperative program example

The above C program creates the customer structure. Structure types are a prime example of data abstraction in C. The program demonstrates how to create, update, and display commands via gen structure variables.

All of these orders are in a main() function, which is a process overall that tells how much money the customer should pay for the order. Executing the above program will generate the following output in your console.

2. Object Oriented Programming

The object-oriented programming paradigm began in the 1990s. This paradigm is a descendant of imperative. However, the object-oriented paradigm stores state in objects and not in variables. Programming languages ​​that use the object-oriented paradigm often handle complex applications better.

The main features of the paradigm are objects, classes, data encapsulation, inheritance, and polymorphism. A class is a fundamental component of an object-oriented program. Some classes inherit properties and operations from other classes. Programmers describe it as a parent-child relationship.

This subtype falls under the category of polymorphism. Classes contain tools to hide and protect sensitive data through encapsulation. Once you have defined a class, you can use it to create objects. The three more popular programming languages ​​that use the object-oriented paradigm are Java, C++, and Python.

An object-oriented program example

This application demonstrates most of the features of the object-oriented programming language, Java. A specific type of customer inherits behavior from a more general type. All clients implement an interface. The specific customer type overrides a method from the interface.

Discountable.java file

The above code creates an interface. In Java, an interface is another example of polymorphism. This allows entities that are not directly related to access the same properties, such as the GrandTotal method. The application is focused on Customers, but an Employee class can also have use for the Discountable interface.

client.java file

The above code creates the Customer class. It implements the Discountable interface, then uses its own method to calculate and display a grand total based on the category of the customer.

The protected keyword in the above code is an example of data encapsulation; It restricts access to data created through this class. Therefore, only subclasses (or child classes) of the Customer class will have access to its data.

NewCustomer.java file

The above code creates a new Customer class which extends the Customer class. This Java class uses inheritance to represent the parent-child relationship with the Customer class.

NewCustomer is the child of the relation, therefore, it has access to all the properties of the Customer class. It imports the attributes of the Customer class using the super() method.

3. Functional Programming

The key concepts of this paradigm are expressions, functions, parametric polymorphism, and data abstraction. Expressions are a fundamental component of the functions used by functional programming languages.

Parametric polymorphism is one of three types of polymorphism. This type facilitates general programming through functions and types. JavaScript is one of the most popular functional programming languages.

Leave a Reply

Your email address will not be published. Required fields are marked *