Docsity

Programming Paradigms: Procedural vs. Object-Oriented Approaches, Schemes and Mind Maps of Computer science

Partial preview of the text

Download Programming Paradigms: Procedural vs. Object-Oriented Approaches and more Schemes and Mind Maps Computer science in PDF only on Docsity!

Programming Paradigms

Content

Procedural Programming Object-Oriented Programming Abstraction Encapsulation Inheritance Polymorphism Event-Driven Programming

Characteristics of Procedural

Programming

It focuses on process rather than data. It takes a problem as a sequence of things to be done such as reading, calculating and printing. Hence, a number of functions are written to solve a problem. A program is divided into a number of functions and each function has clearly defined purpose. Most of the functions share global data. Data moves openly around the system from function to function.

Procedural Programming

What’s drawback with procedural programming language?  (^) When requirements change It hard to implement new feature that were not planned in the beginning. Code blocks gets bigger and bigger. Changes in code introduce many bugs. Code gets hard to maintain.

Features

Object-oriented programming provides the following features: Abstraction Encapsulation Inheritance Polymorphism

Abstraction

Abstraction is the feature of extracting only the required information from objects. Hide unnecessary details which are irrelevant for current purpose (and/or user). Reduces complexity and aids understanding. For example, consider a television as an object. It has a manual stating how to use the television. However, this manual does not show all the technical details of the television, thus, giving only an abstraction to the user.

Encapsulation

Inheritance

Inheritance is the process of creating a new class based on the attributes

and methods of an existing class.

The existing class is called the base class whereas the new class created

is called the derived class.

This is a very important concept of object-oriented programming as it

helps to reuse the inherited attributes and methods.

Purpose

The purpose of inheritance is to reuse common methods and attributes among classes without recreating them. Reusability of a code enables you to use the same code in different applications with little or no changes.

Example

Consider a class named Animal which defines attributes and behavior for animals. If a new class named Cat has to be created, it can be done based on Animal because a cat is also an animal. Thus, you can reuse the code from the previously-defined class.

Example

class Area { static int CalculateArea(int len, int wide) { return len * wide; } static double CalculateArea(double valOne, double valTwo) { return 0.5 * valOne * valTwo; } static void Main(string[] args) { int length = 10; int breadth = 22; double tbase = 2.5; double theight = 1.5; Console.WriteLine(“Area of Rectangle: “ + CalculateArea(length, breadth)); Console.WriteLine(“Area of triangle: “ + CalculateArea(tbase, theight)); } } Output Area of Rectangle: 220 Area of triangle: 1.

Event-driven programming

 Event-driven programming is a programming paradigm in which

the flow of the program is determined by events such as user

actions

Event-driven programming is the dominant paradigm used in graphical user interfaces and other applications that are centered on performing certain actions in response to user input

Key features and characteristics of event-

driven programming

Trigger Functions Trigger functions in event-driven programming are a functions that decide what code to run when there are a specific event occurs, which are used to select which event handler to use for the event when there is specific event occurred  Events Events include mouse, keyboard and user interface, which events need to be triggered in the program in order to happen, that mean user have to interacts with an object in the program  Simplicity of Programming and Ease of Development Event-driven programming is simple and easier to program compared to other type of programming as it’s very visual Event-driven programming also easy for user to insert a pre-written code scripts into an existing application because it allows user to pause the code while it’s running