Explain what is meant by a Programming Paradigm and the main characteristics of Procedural, Object oriented and Event-driven paradigms and the relationships among them. Write small snippets of code as example for the above three programming paradigms using a suitable programming language(s). you also need to critically evaluate the code samples that you have given above in relation to their structure and the unique characteristics.
Programming paradigm is a ay or style of programming.
1. Procedural paradigms
- Focuses on sequence of action to be done.
- It is implemented based on actions.
Example
#include <iostream>
int sum(int n1, int n2);
int main () {
int a = 10;
int b = 20;
int res;
res = sum(a, b);
std::cout << a << "+" << b << "=" << res << std::endl;
return 0;
}
int sum(int n1, int n2) {
int res;
res = n1 + n2;
return res;
}
2. Object oriented paradigms
- encapsulation
- polymorphism
- inheritance
Example
class Dog {
constructor(name, birthday) {
this.name = name;
this.birthday = birthday;
}
_attendance = 0;
getAge() {
return this.calcAge();
}
calcAge() {
return Date.now() - this.birthday;
}
bark() {
return console.log("Woof!");
}
updateAttendance() {
this._attendance++;
}
}
3. Event-driven paradigms
- Servise oriented
- Time driven
Example
import asyncio
def hello_world(lp):
print('Hello World')
lp.stop()
lp = asyncio.get_event_loop()
lp.call_soon(hello_world, lp)
lp.run_forever()
lp.close()
Comments
Leave a comment