Uploaded by darshan krishan

LO2 Explain the characteristics of procedural

advertisement
LO2 Explain the characteristics of procedural, object-orientated and event-driven
programming, conduct an analysis of a suitable Integrated Development Environment
(IDE)
Programming paradigm
The way or style of programming is known as programming paradigm. Not all the paradigms
are easy to write the language. This also could be understood as the fundamental building
structure and elements of the program. A programming language is not only supported with a
single paradigm, it could consists a multiple paradigms. The main six programming paradigm
are mentioned below. The arising of paradigms is due to lower level thinking of every options
at a particular time.

Imperative – This focus much on the working of a system. The statement used in this
paradigm changes the state of the program.

Declarative – the result of the programme is expected but not the way it reaches the
results.

Structured – To use the structured control flow of a computer program, this
programming paradigm improves the quality, clarity, and development time.

Procedural – this paradigm is based on the concept of procedure call derived from the
structured programming

Functional – the way that the structure and elements is built in a computer programming
that improves the mathematical functions, avoids state changing and data that can be
changed.

Object oriented – Objects that communicate with one another to work. Each of these
objects has its own public and internal interfaces. There two types of object orientation.
o Class-based: The object state and behaviour is accordingly to the class it
belongs.
o Prototype- based: behaviour is gained from prototype objects.

Event-Driven – the actions performed with the flow of the program is determined by
events such as mouse clicks, pressing a key from other programs.
Procedural Paradigm
The performance of procedural programming is done step by step. The function is separated
into smaller sections and then solved.The procedural code is the code that tells a device how to
do a task in a logical order. This paradigm takes a top-down, linear approach to data and
methods, and sees them as two different things. Procedural Programming separates a program
into procedures, which are sometimes known as routines or functions and simply include a set
of actions to be carried out, based on the concept of a procedure call. Simply put, procedural
programming is writing down a list of instructions that teach the computer how to complete a
task step by step.
Some of the main features of procedural paradigm is mentioned below,

Predefined functions
A defined function is usually an instruction with a name attached to it.
Predefined functions are usually included in higher-level programming
languages, however they are taken from a library or registry rather than a
program. ‘charAt()' is an example of a pre-defined function that looks for a
character value in a string.

Local Variable
A local variable is a variable that is declared in the method's main structure and
is only valid inside the scope of the method. The local variable can only be used
in the method in which it is defined; if it is used outside of that function, the
code will fail.

Global Variable
A global variable is one that is declared outside of every other function in the
program. As a result, unique local variables, global variables can be used in any
function.

Modularity
When 2 different systems are given two different tasks to complete, they are
grouped together to complete a bigger task first. The tasks of each set of systems
would next be completed one by one until all tasks were completed.

Parameter Passing
A system for passing parameters to functions, subroutines, and procedures is
known as parameter passing. ‘Pass by value', ‘pass by reference', ‘pass by
result', ‘pass by value-result', and ‘pass by the name' are all methods for passing
parameters.
Object oriented paradigm
The primary idea behind OOP (Object Oriented Programming) is that messages are
passed between objects. Methods are the responses provided by these objects when
they conduct operations. These communications may contain arguments of their own.
Objects in Python are organized into classes, with each class serving as a description
for a group of related objects. A class instance is referred to as an object. The primary
qualities of OOP are as follows:
 Encapsulation / Information hiding
This is the concept of grouping data and operations within a class. This encapsulation
is used to hide an object's internal state from the outside environment via way using.
Methods only the data is available. The objects are made independent and allows to
reuse objects in other applications. This makes maintenance easier.
Figure 1 : Encapsulation
 Inheritance
The classes can categorized into an order when some common features look among
them. This allows to derive new classes from the existing classes. When a class is
derived from another class the host class is known as the parent class or super class.
New class formed from an existing class is called as a Sub class or child class.
Child class or sub class get all the data and operations from a Super or parent class. In
addition a sub class can contain its own data. A simple diagram is given below to
understand inheritance further.
Animal
Vegetarian
Deer
Meat-eater
Lion
Omnivore
Fox
Human
The inheritance can be categories into six types as follows
 Single inheritance
A derived class can inherit properties and behavior from a single parent class using
single inheritance. It allows a derived class to inherit the characteristics and behavior
of a base class, allowing for code reuse as well as the addition of new features.
 Multi-level inheritance
Is the concept of a single class extending (or saving) many base classes.
 Multiple inheritance
A derived class takes a base class in multilevel inheritance, and the derived class also
works as the base class for other classes.
 Multipath inheritance
It's possible that a child will have two parent classes in a two-level inheritance. The two
parent classes, on the other hand, could be developed from a single grandparent class.
 Hierarchical inheritance
A type of inheritance in which more than one class is inherited from a single parent or
base class is known as hierarchical inheritance. The base class shares many of the same
properties as the parent class, especially those that are common in the parent class.
 Hybrid inheritance
Simple, multiple, and hierarchical inheritance are all mixed in hybrid inheritance. A
class is usually derived from two classes in multiple inheritances, with one of the parent
classes being a derived class rather than a base class.
Consider some of the advantages and disadvantages of inheritance.
 Code redundancy reduced

Reusability of code

Improves readability of code by reducing the source code size

Code is managed easily by diving into parent and child classes

Due to binding of parent class and child classes, any changes made to the parent class
is affected to all child classes

In a class hierarchy many data remains unused and memory is allocated is not utilized.
Hence, program is affected if inheritance is not implemented correctly.
 Polymorphism
Polymorphism refers to the ability to take on multiple forms. It can also be used to refer
to the ability to modify methods for derived classes. When it comes to OOP, the ability
to produce multiple (many) results with a single operation is important.
Triangle
Draw ()
Results
Rectangle
Shape
Draw ()
Draw ()
Circle
Draw ()
Figure 2 : Example of Polymorphism
Event-Driven
Event driven program is the reply given to the user events or similar input. The idea of event
driven program is planned to react. In other words, event driven can be expressed, as the flow
of program executed is determined through the events.
Some characteristics of events driven paradigms
 Service oriented
This is a programming paradigm that is used to write program that are specifically made
for services. The request made by the user is satisfied. For example when the close
button is press the application exits
 Time driven
The code is setup to execute on a routine basis. This could be used to run a part of the
code that is configured to run at a specified time. The update that appears when the
system has a new release is an example of this. It asks the user whether or not they
want to update by checking for updates on a time basis.
 Event handlers
This function or method takes place when an event happens, when an event takes place
they are performed I reply. For example, clicking a button one or many times the code
is performed.
 Trigger functions
The decision of code, which should be run when an event happens, is implemented by
this trigger function.
 Events
When the user relate with the object, for the events to take place it has to be triggered.
Getting a click to a button by a mouse can trigger events in many ways. The events
occur due to the code being assigned for a button. Not only mouse even keyboards can
be used to set create events.
Relationships of the Procedural, Object-oriented and event driven programming
“Procedural programming means that you define a program and its subprograms as a series
of steps. In contrast, declarative programs try to describe the result without regard to the steps
taken to computer it but rather some description or denotation of the desired result.
Object oriented programming is a way of organizing code around the principles of
encapsulation, inheritance, substitution, programming to interfaces, and so on. Object oriented
programs are usually mostly procedural.
Event based programming is about writing event handling procedures and having the core
event loop provided by the underlying system. In this way, you can save the trouble of writing
your own event loop and benefit from various libraries that already work with the system
provided event loop. Event based programs are very often writing using object oriented style,
but not always.
These three categories are thus not related strictly hierarchically, but in common usage they
are mostly nested within one another.” (Vandermeer, 2020)
Example Code for the Programming paradigms (Code and Output)
 Procedural Paradigm
Figure 3 : Procedural Paradigm Code
Figure 4 : Procedural Paradigm Output
The procedural paradigm example is given above. H is the height, W is the Width if we need
to get an area we need to multiple the Vales The output is according done one by one in the
Values mentioned in the figure 5.
 Object oriented program
Objects of are basic building blocks of OOP in C#.A combination of data and method
is known to be an object. Data and methods are the members of an object. The objects
created in OOP program are connected together via methods. Every object can send
messages, receive messages and process data.
In creating an object there two this s to consider. First, a class is defined. An objects
template is a class. It is a blueprint, which particularly describes the performance and
state that objects of the class shared by all. Many objects can be created using a class.
Objects that are created at the runtime of a class are recognized as examples of that
relevant class.
Figure 5 :OOP example
In the above example, simple object is created.
This show is a simple class where the body of the template is empty. There are no any data or
methods.
A new instance of subject class is created. A keyword new and a variable su is used to handle
the object created.
The object is printed to comfort to get some basic data of the object. Considering the reason
to use print option to an object. When an object is printed it is called to its Tostring () method.
But theatre are no any methods yet defined. When the objects are created su is inherited from
base object.
Some elementary functions are share among all created objects.
The object class name returned as a result.
 Event-Driven paradigm
Event-driven programming is a programming paradigm in which events, such as a user
action such as a mouse click or key press, or a message from the operating system or
another program, determine the flow of program execution. An event-driven
application is one that activates events as they happen and responds with an appropriate
event-handling technique. The concept is based on interrupt-driven programming,
which was popular in early command-line environments like DOS and embedded
computers. the following mentioned diagram is an example for event driven paradigm.
The developer creates a login form for the system and the login buttons code is stated.
When the button “Login” is clicked after entering the correct Username and Password
the next Main form of the system appears. The process done when a click is made to
the button called as event driven paradigm. In other words, the system responds when
the “login” button is clicked.
Figure 6 : Login From
Figure 7 : Login Button Code
Differences and the Unique Characteristics of Procedural Programming,
Object Oriented Programming and Event-Driven Programming
Procedural
Programming
Object Oriented Programming Event-Driven Programming
Provide character user
interface to write the
commands.
Provide command writing in
modules.
Provide graphical user
interface to create the
program.
Low data security.
High data security.
It’s tightly connected to the
declarative programming.
Writing code is relatively
simple.
Writing code is harder.
Basic elements are variables
and functions.
Hierarchical structured
program.
Graph structured program.
Widely used in graphical user
interface.
Less flexibility.
More flexibility.
More flexibility.
Download