Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

An overview of two fundamental programming paradigms: procedural programming and object-oriented programming (oop). It explains the key features and characteristics of each approach, including procedural programming's focus on process and algorithms, and oop's emphasis on data and concepts like abstraction, encapsulation, inheritance, and polymorphism. The document also discusses the drawbacks of procedural programming, such as difficulty in implementing changes and maintaining code, and how oop was introduced to address these issues. Additionally, the document covers the event-driven programming paradigm, which is centered on responding to user actions and events. This comprehensive overview of programming paradigms can be valuable for students and learners interested in understanding the fundamental concepts and approaches in software development.

Typology: Schemes and Mind Maps

2021/2022

Uploaded on 08/11/2023

thanh-nguyen-c0y
thanh-nguyen-c0y 🇻🇳

1 document

1 / 19

Toggle sidebar

Related documents


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

Procedural Programming

Programmer implements requirement by breaking down them to small steps (functional decomposition). Programmer creates the “recipe” that computer can understand and execute. A program in a procedural language is a list of instruction where each statement tells the computer to do something. It focuses on procedure (function) and algorithm is needed to perform the computation.

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.

Object-Oriented Programming

Programming languages are based on two fundamental concepts, data and ways to manipulate data. Traditional languages such as Pascal and C used the procedural approach which focused more on ways to manipulate data rather than on the data itself. This approach had several drawbacks such as lack of re-use and lack of maintainability. To overcome these difficulties, OOP was introduced, which focused on data rather than the ways to manipulate data. The object-oriented approach defines objects as entities having a defined set of values and a defined set of operations that can be performed on these values.

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

Details of what a class contains need not be visible to other classes and

objects that use it.

Instead, only specific information can be made visible and the others

can be hidden.

This is achieved through encapsulation, also called data hiding.

Both abstraction and encapsulation are complementary to each other.

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.

Example

Consider a class called Vehicle that consists of a variable called color and a method called Speed(). These data members of the Vehicle class can be inherited by the TwoWheelerVehicle and FourWheelerVehicle classes. The following figure illustrates an example of inheritance:

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.

Polymorphism

Polymorphism is the ability to behave differently in different situations.

It is basically seen in programs where you have multiple methods

declared with the same name but with different parameters and

different behavior.

The following methods in a class have the same name but different

signatures that perform the same basic operation but in different ways:

 (^) Area(float radius)  (^) Area(float base, float height)

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

Service Oriented Service oriented is a key features in event-driven programming that used to write programs that are made for services and it takes does not slow down the computer as service oriented only consume little of the computer processing power and usually services run in the background of OS  Time Driven In event driven programming, time driven is a paradigm, it’s a code that runs on a time trigger, time driven can be a specific code that runs on a specific time, which could be once an hour, once a week or once a month, this means it’s a pre-set to do task  Event Handlers Event handlers is a type of function or method that run a specific action when a specific event is triggered

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